在jQuery数据表中将多个参数传递给sAjaxSource

时间:2016-09-26 12:32:28

标签: jquery asp.net datatables

我有jquery数据表 我需要传递2个参数,此代码不起作用 也许不会调用程序

    var params = {
        "name": "ProgressivoRichiesta", "value": $("input[name='<%=txtTargaResponsabile.UniqueID%>']").val(),
        "name": "sDataIncidente", "value": $("input[name='<%=txtDataSinistro.UniqueID%>']").val()
    }

   $('#listReceivedMail').DataTable({
            destroy: true,
            "dataType": 'json',
            "contentType": "application/json; charset=utf-8",
            "type": "GET",
            "url": "CinfoService.svc/ProcedureName",
            "data": params,

感谢

1 个答案:

答案 0 :(得分:1)

要按照您目前正在进行的方式传递参数,需要进行以下更改:

var model = { ProgressivoRichiesta: $("input[name='<%=txtTargaResponsabile.UniqueID%>']").val(),
              sDataIncidente: $("input[name='<%=txtDataSinistro.UniqueID%>']").val()
};

$('#listReceivedMail').DataTable({
            destroy: true,
            "dataType": 'json',
            "contentType": "application/json; charset=utf-8",
            "type": "GET",
            "url": "CinfoService.svc/ProcedureName",
            "data": JSON.stringify(model),

但要使用API​​传递它们,您需要这样做:

$('#listReceivedMail').DataTable({
        "ajax": {
                 "url": "CinfoService.svc/ProcedureName",
                 "data": function ( d ) {
                     return $.extend( {}, d, {
                        ProgressivoRichiesta: $("input[name='<%=txtTargaResponsabile.UniqueID%>']").val(),
                        sDataIncidente: $("input[name='<%=txtDataSinistro.UniqueID%>']").val()
                     });
                 }
            },