php 如何在jquery数据表的ajax调用中发布参数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25505755/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to post the parameter in ajax call of jquery datatable
提问by chaya
As of now I am passing parameter along with URL in ajax call of data table.
截至目前,我正在数据表的ajax调用中传递参数和URL。
But I want to pass it as POST
method, please anyone one help me regarding parameter passing in post method, here's my trial code:
但我想将它作为POST
方法传递,请任何人帮助我了解 post 方法中的参数传递,这是我的试用代码:
// Sending through GET
var $table = $('#example').dataTable(
"processing": true,
"serverSide": true,
"bDestroy": true,
"bJQueryUI": true,
"ajax": 'getResult.php?formName=afscpMcn&action=search&mcn_no='+mcnNum+'&cust_nm='+cust_num+'&emp_id='+emp+''
});
回答by Kevin
Just pass it like a normal jQuery ajax in POST fashion.
只需像普通的 jQuery ajax 一样以 POST 方式传递它。
The structure should look like this:
结构应如下所示:
ajax: { type: 'POST', url: <path>, data: { your desired data } }
Example:
例子:
var $table = $('#example').dataTable(
"processing": true,
"serverSide": true,
"bDestroy": true,
"bJQueryUI": true,
"ajax": {
'type': 'POST',
'url': 'getResult.php',
'data': {
formName: 'afscpMcn',
action: 'search',
// etc..
},
}
});
In PHP, just access the POST indices as usual (just the straightforward approach):
在 PHP 中,只需像往常一样访问 POST 索引(只是简单的方法):
getResult.php
getResult.php
$form_name = $_POST['formName'];
// the rest of your values ...
回答by bharat
You can try this way:
你可以试试这个方法:
$('#example').dataTable( {
"ajax": {
"url": "data.json",
"data": function ( d ) {
d.extra_search = $('#extra').val();
}
}
});
回答by Abdullah Sheikh
$("#tbl").dataTable({
oLanguage: {
sProcessing: '<div id="loader"></div>'
},
bProcessing: true,
"bServerSide": true,
"iDisplayLength": pageSize,
"sAjaxSource": " /PurchaseOrder/AddVendorItems", // url getData.php etc
"fnServerData": function ( sSource, aoData, fnCallback, oSettings ) {
aoData.push({ "name": "where", "value": ID +" AND ISNULL(IsFinal,0) = "+ ($("#chkFinal").bootstrapSwitch('state') == true ? 1 : 0) });
aoData.push({"name": "PackIDFK", "value": $("#PackIDFK").val()}) //pushing custom parameters
oSettings.jqXHR = $.ajax( {
"dataType": 'json',
"type": "POST",
"url": sSource,
"data": aoData,
"success": fnCallback
} );
} });
This is real time example.The aoData contains all the parameters which is required on server side and you can also push your own custom parameters
这是实时示例。 aoData 包含服务器端所需的所有参数,您也可以推送自己的自定义参数