2012-02-08 59 views
2

我對jQuery AJAX非常熟悉並一直使用它。 Kendo UI建立在jQuery之上,並且使用了AJAX。與&傳遞參數的接口到一個HttpHandler是很容易使用jQuery,你只需做到以下幾點:如何使用Kendo UI將參數傳遞給HttpHandler?

使用jQuery AJAX:

$.ajax({ 
    complete: self.onComplete, 
    data: { SiteId: 777 }, // <--- this gets appended to the post 
    dataType: 'json', 
    error: self.onError, 
    success: self.onSuccess, 
    url: self.url 
}); 

我的問題:
我試圖找到KendoUI等同於data(以上)。

  • 雖然網格是否與從該參數不被饋送到的HttpHandler所述的HttpHandler
  • 傳遞迴我填充數據(見下文)

劍道代碼如下所示:

<script type="text/javascript"> 

     $(document).ready(function() { 

      var dataSource = new kendo.data.DataSource({ 
       transport: 
        { 
         read: { 
          url: "Handlers/Attempt1Synch.ashx", 
          dataType: "json", 
          contentType: "application/json; charset=utf-8", 
          type: "POST", 
          data: { SiteId: 777 } 
         } 
//      parameterMap: function (data, operation) { 
//       return JSON.stringify(data); 
//      } 
        }, 
       schema: { data: "People" } 
      }); 

      $("#grid").kendoGrid({ 
       height: 360, 
       width: 500, 
       dataSource: dataSource, 
       groupable: true, 
       scrollable: true, 
       sortable: true, 
       pageable: true, 
       columns: 
       [{ 
        field: "Id", 
        width: 0 
       }, 
       { 
        field: "FirstName", 
        width: 90, 
        title: "First Name" 
       }, 
       { 
        field: "LastName", 
        width: 90, 
        title: "Last Name" 
       }, 
       { 
        width: 100, 
        field: "City" 
       }, 
       { 
        field: "Title" 
       }, 
       { 
        field: "BirthDate", 
        title: "Birth Date", 
        template: '#= kendo.toString(BirthDate,"dd MMMM yyyy") #' 
       }, 
       { 
        width: 50, 
        field: "Age" 
       }] 
      }); 
     }); 
    </script> 

    <div id="grid"> 
    </div> 

MY HTTP處理程序類似:

public class Attempt1Synch : IHttpHandler 
{ 
    public void ProcessRequest(HttpContext context) 
    { 
     var siteId = Convert.ToInt32(context.Request["SiteId"]); 

     var serializer = new JavaScriptSerializer(); 
     var response = mock(siteId); 

     context.Response.ContentType = "text/json"; 
     context.Response.Write(serializer.Serialize(response)); 
     context.Response.End(); 
    } 

    public bool IsReusable 
    { 
     get 
     { 
      return false; 
     } 
    } 
} 

回答

3

我來看看,這是他們以前的版本中的已知問題。 The newest release fixes this。因此,如下圖所示,你必須首先下載最新版本的KendoUI

V1 2011 SP1(版本2011.3.1407) - 2012年2月
- 見 '的OData不提交用戶定義的參數'

但是,還有上面的代碼的問題。代碼應該總共省略POST命令。

新的數據源應該是這樣:
只有DataSource對象是不正確。新的應該看起來像這樣 -

var dataSource = new kendo.data.DataSource({     
    transport:      
    {       
     read: 
     { 
      url: "Handlers/Attempt1Synch.ashx", 
      dataType: "json", 
      contentType: "application/json; charset=utf-8", 
      data: { SiteId: 777 } 
     }, 
     schema: { data: "People" }    
}); 
+0

謝謝你的答案。你推薦任何關於Kendo UI的博客或教程。我發現Telerik的文檔和示例缺乏。 – 2014-10-31 19:31:32

+0

不,我很抱歉我不得不通過這個使用'試錯法'來解決這個問題。是的,Telerik的文檔網站確實很糟糕。 – 2014-11-05 13:29:42