Jquery DataTable将参数传递给ajax调用asp.net [英] Jquery DataTable passing a parameter to ajax call asp.net

查看:431
本文介绍了Jquery DataTable将参数传递给ajax调用asp.net的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是我的代码,其中我向我的web方法发送一个ajax调用,并从服务器获取数据来填充我的HTML表,可以看到我正在使用Jquery DataTables来完成任务,并且它正常工作数据表({
ajax:{
dataType:$ {

$ b

  $ 'json',
contentType:application / json; charset = utf-8,
type:POST,
url:index.aspx / Risky ,
dataSrc:function(json){
return $ .parseJSON(json.d);
}
},
columns:[
{data:Prctice_Group_Risk_No},
{data:Practice_Group},
{data:Risk_Category},
]
});

我的问题是我如何传递这个ajax调用的参数?我已经看到无处不在的网络,但所有这些例子是关于服务器端处理的地方,但在这里我正在使用客户端处理,我没有使用fnsServerData或fnServerParams,任何人可以帮助我知道如何传递参数与我的ajax调用?

解决方案

使用 ajax.data 选项可以在Ajax请求时添加或修改提交给服务器的数据。



数据表({
ajax:{
dataType:'json',
contentType :application / json; charset = utf-8,
type:POST,
url:index.aspx / Risky,
data函数(d){
d.extra_search = $('#extra')。val();
},
dataSrc:function(json){
return $ .parseJSON(json.d);
}
},
columns:[
{data:Prctice_Group_Risk_No},
{data :Practice_Group},
{data:Risk_Category},
]
});


below is my code in which I send an ajax call to my web method and get data from server to populate my HTML table, as you can see I am using Jquery DataTables to accomplish the task, and it is working fine

  $('#example').DataTable({
            "ajax": {
                "dataType": 'json',
                "contentType": "application/json; charset=utf-8",
                "type": "POST",
                "url": "index.aspx/Risky",
                "dataSrc": function (json) {
                    return $.parseJSON(json.d);
                }
            },
            "columns": [
                { "data": "Prctice_Group_Risk_No" },
                { "data": "Practice_Group" },
                { "data": "Risk_Category" },
            ]
        });

my question is how can i pass a parameter with this ajax call? I have seen everywhere on net but all those examples are about where its server side processing but here i am am using client side processing , I am not using fnsServerData or fnServerParams , Can anyone help me know how to pass a parameter with my ajax call?

解决方案

Use ajax.data option to add or modify data submitted to the server upon an Ajax request.

$('#example').DataTable({
   "ajax": {
       "dataType": 'json',
       "contentType": "application/json; charset=utf-8",
       "type": "POST",
       "url": "index.aspx/Risky",
       "data": function (d) {
          d.extra_search = $('#extra').val();
       },
       "dataSrc": function (json) {
           return $.parseJSON(json.d);
       }
    },
    "columns": [
        { "data": "Prctice_Group_Risk_No" },
        { "data": "Practice_Group" },
        { "data": "Risk_Category" },
     ]
});

这篇关于Jquery DataTable将参数传递给ajax调用asp.net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆