我对 jQuery AJAX 非常熟悉,并且一直在使用它。Kendo UI 建立在 jQuery 之上,并使用 AJAX。使用 jQuery 与和传递参数到 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>
我的 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;
}
}
}