2

我对 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;
        }
    }
}
4

1 回答 1

3

我发现这是他们以前的版本中的一个已知问题。 最新版本解决了这个问题。因此,您必须首先下载最新版本,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" }             
});
于 2012-02-08T16:10:17.060 回答