Thursday, March 16, 2017

Datatables.net ajax response fails whilst jquery ajax does not

I am currently working with the https://datatables.net/ plugin and am experiencing something really strange.

On page load, 50% of the time the ajax response via datatables is ok and the data loads, but the other 50% it fails and complains of an internal 500 error.

I have the datatables.net call like this -

    historyTable = $('#historyTable').DataTable(
                {
                    "ajax":
                            {
                                "url": "http://localhost/history.php", 
                            },
                    "order": [[ 2, "desc" ]],  

                    // ....  

Now to debug I did the same but in jquery -

jQuery.ajax({
        url: "http://localhost/history.php",
        dataType : 'json',
        success: function (result) 
        {
            console.info(result);
        }
    });

The really strange thing is that when the dataTables ajax call fails it logs this to console

GET http://localhost/history.php 500 (Internal Server Error)

The jquery logs -

Object {data: Array[169]}

I am completely baffled. I have tried removing the dataType json from jquery ajax call and still makes no difference.

Any advice on how to debug this further to work it out?



via GeekInDisguise

Advertisement