jQuery dataTables不会发送POST数组

时间:2015-09-11 23:12:05

标签: php jquery ajax post datatables

我有一个DataTable,它不会通过POST数组传递数据参数。库文档(https://datatables.net/reference/option/ajax.data)中的示例似乎表明此语法是正确的,但调用的PHP文件中的$ _POST数组的print_r表示POST数组为空。

$(document).ready(function() {
var mydatatable = $("#mydatatablediv").DataTable(
{
    "ajax":{
        "url": "path-to-server/backendfile.php",
        "contentType": "application/json",
        "type": "POST",
        "data": {"myeventid":"5"} //replaced with variable in production
    }, //end ajax parameter
    "columns": [
        {"data":"field1","width":"30%"},
        {"data":"field2","width":"20%"},            
        {"data":"field3","width":"5%"},
        {"data":"field4","width":"30%"},
        {"data":"field5","width":"5%"}
    ],
    "paging":false,
    "info":false
});//end dataTable
});//end DOM load

1 个答案:

答案 0 :(得分:1)

Removing the "contentType": "application/json" parameter resolved the issue. I had added this parameter per the DataTables website documentation at https://datatables.net/reference/option/ajax.data under the 'Submit data as JSON in the request body' section. But as stated, this is not necessary.