如何在jquery数据表的ajax调用中发布参数

截至目前,我在数据表的ajax调用中传递参数和URL。

但是我想把它作为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+'' }); 

只需将其传递给POST方式的普通jQuery ajax即可。

结构应如下所示:

 ajax: { type: 'POST', url: , data: { your desired data } } 

例:

 var $table = $('#example').dataTable( "processing": true, "serverSide": true, "bDestroy": true, "bJQueryUI": true, "ajax": { 'type': 'POST', 'url': 'getResult.php', 'data': { formName: 'afscpMcn', action: 'search', // etc.. }, } }); 

在PHP中,只需像往常一样访问POST索引(只是简单的方法):

getResult.php

 $form_name = $_POST['formName']; // the rest of your values ... 

DataTables手动输入

 $("#tbl").dataTable({ oLanguage: { sProcessing: '
' }, 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 } ); } });

这是实时示例.aoData包含服务器端所需的所有参数,您也可以推送自己的自定义参数