C# 如何使用JQuery数据表从web方法正确地重新加载数据?

C# 如何使用JQuery数据表从web方法正确地重新加载数据?,c#,jquery,asp.net,ajax,jquery-datatables,C#,Jquery,Asp.net,Ajax,Jquery Datatables,我正在使用JQuery插件处理我的表,最近我切换到服务器端分页和筛选。特别是,我有一个web方法,可以返回数据来填充customers表: [WebMethod] [ScriptMethod(ResponseFormat = ResponseFormat.Json)] public string GetCustomers(string jsonAOData, int mode) { // ... } 在我的页面中,我使用这些代码通过AJA

我正在使用JQuery插件处理我的表,最近我切换到服务器端分页和筛选。特别是,我有一个web方法,可以返回数据来填充customers表:

    [WebMethod]
    [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
    public string GetCustomers(string jsonAOData, int mode)
    {
        // ...
    }
在我的页面中,我使用这些代码通过AJAX调用检索数据

var grid = $('#grid').dataTable({
        bJQueryUI: true,
        bLengthChange: false,
        iDisplayLength: listItemsPerPage,
        bDestroy: true,
        "bProcessing": true,
        "bSort": true,
        "sPaginationType": "full_numbers",
        "bServerSide": true,
        "sAjaxSource": "/wsData/GetData.asmx/GetCustomers",
        "fnServerData": function (sSource, aoData, fnCallback) {

            var jsonAOData = JSON.stringify(aoData);

            $.ajax({
                //dataType: 'json', 
                contentType: "application/json; charset=utf-8",
                type: "POST",
                url: sSource,
                data: "{jsonAOData : '" + jsonAOData + "', mode:'0'}",
                success: function (msg) {
                    fnCallback(JSON.parse(msg.d));
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    alert(XMLHttpRequest.status);
                    alert(XMLHttpRequest.responseText);
                }
            });
        },
        "aoColumnDefs": [
            // my columns structure
        ]
    });
如您所见,我将向web方法传递两个参数:
jsonAOData
,其中包含分页和筛选的所有信息,以及定义如何从DB获取数据的
模式。
它工作得很好,但现在我需要重新加载表中的数据,并将
模式的不同值传递给我的web方法

阅读我发现的文档功能可以帮助我,但我找不到正确的方法将其应用于我的问题

我试着这样做:

grid.fnReloadAjax("/wsData/GetData.asmx/GetCustomers?mode=1");
但它不起作用。你能帮助我吗?我哪里做错了


如何将新参数传递给我的web方法?

无法立即发现缺少/错误的内容,但这是我的版本

$(document).ready(function () {
        jQuery.support.cors = true;

        var sAjaxSourceUrl = '@ViewBag.sAjaxSourceUrl' //passing mine from MVC3 viewbag, but you can hard-code it
        var dt = $('#dataTable').dataTable({
            "bProcessing": true,
            "bSort": true,
            "bServerSide": true,
            "sServerMethod": "POST",
            "sAjaxSource": sAjaxSourceUrl,
            "fnServerData": function (sSource, aoData, fnCallback) {
                var jsonAOData = JSON.stringify(aoData);
                $.ajax({
                    crossDomain: true,
                    type: "POST",
                    url: sSource,
                    data: jsonAOData,
                    dataType: "json",
                    contentType: "application/json; charset=utf-8",
                    success: function (data) {
                        fnCallback($.parseJSON(data));
                    },
                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                        alert("Status: " + XMLHttpRequest.status + "\r\n" + textStatus + "\r\n" + errorThrown);
                    }
                });
            },
            "aoColumnDefs": [
// my columns structure
],
            "sScrollY": "500",
            "bScrollCollapse": true
        });

我发现
fnReloadAjax()
对我来说不太好。 因此,在一些论坛之后,我决定使用
fnDraw()

我定义了一个全局变量
mode
,根据要检索的数据对其进行取值。 然后我调用
fnDraw()
。从web方法加载数据时重新绘制该表

在AJAX调用中,我设置:

data: "{jsonAOData : '" + jsonAOData + "', mode:'" + mode +"'}",

注意:我的有跨域设置…但是它们在同一个域调用上没有(用户注意到的)区别。