callback every time the server side query is run

callback every time the server side query is run

GeorgeHelmkeGeorgeHelmke Posts: 44Questions: 16Answers: 0

I don't always get good data back from the server, but I am always able to include an error message. I pick that message up with a callback, and display it to the user. I have gotten it to work with initComplete, but that only fires when the table is first initialised.

What I need to do is be able to do the same thing, but after the user has typed in some search text, and it comes back sour.

For reference, here is the initComplete callback specifier used when I define the table:

        "initComplete": function(settings, json) {
            console.log("init complete, error msg: " +json.sErrorMessage);
            $("div#ErrorMessage h2").text(json.sErrorMessage);

This question has an accepted answers - jump to answer


  • allanallan Posts: 56,837Questions: 1Answers: 9,035 Site admin
    Answer ✓


    There are two options here:

    1) Use the built in error handling by returning an error parameter in the JSON object where the value is what the user should see - by default DataTables will display this in an alert() message to the user. For example the following JSON could be used:

      "error": "Could not connect to database - contact support."

    2) Use the xhr event. This is going to be basically the same as your initComplete, but it is triggered every time DataTables makes an Ajax request to get data.

    table.on( 'xhr', function ( e, settings, json ) {
        $("div#ErrorMessage h2").text(json.sErrorMessage);


This discussion has been closed.