2

I have a DataTable that won't pass the data parameter via the POST array. The example from the library documentation (https://datatables.net/reference/option/ajax.data) would seem to indicate that this syntax is correct but a print_r of the $_POST array in the PHP file called indicates that the POST array is empty.

$(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
  • 1
    is the javascript file correctly included in the html file with <script> tag?, does the "mydatatablediv" exist in the html? is the datatable library correctly included with <script> tag on the html?, can you see the ajax request firing on the browser's developer tools? Commented Sep 11, 2015 at 23:30

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.