DataTables ajax call not launching

DataTables ajax call not launching

semmelbroeselsemmelbroesel Posts: 8Questions: 1Answers: 0

Hi.

I have two different sites that use the same code to load data into a table through DataTables. One one site, it works, but not on the other, and I can't find out what is wrong with it...

Let's start with the code:

$('.dataTable').dataTable({
    "ajax": {
        url: '/ajax.php',
        type: 'POST',
    data: {act:'dl', lt:'sch'},
        error: function (xhr, textStatus, error) { console.log(textStatus); }
    }
});

With Firebug in Firefox, I can tell that the one site is launching the Ajax call, but the other site doesn't.

The error function is never called, either.

I have added a plain $.ajax call with the same parameters to see if there might be a problem with the target code, but it displayed the data.

The only difference I can imagine is that I am using slightly newer versions of jQuery and jQuery UI on the site that is not working.

The HTML table in question is setup correctly and includes <tbody></tbody>. All code up to this point works, and the DataTables object is clearly initialized - it changes the content of the table with sorting and searching features, so I know that part is working.

The only thing that is not working is the ajax call.

I removed the datatables reference from my code and manually entered the code above into the console - same thing: It initializes, but makes no ajax call.

I also know that there is only one object with the class dataTable out there, and I even tried the code with adding .first() without a change.

I am using DataTables version 1.10.3, jQuery version 1.9.1, jQuery UI version 1.11.2. Everything else on this site works.

What am I missing?

Thanks!

Replies

  • semmelbroeselsemmelbroesel Posts: 8Questions: 1Answers: 0

    Any thoughts at all? Is there something missing in my code? Is it maybe a jQuery/jQuery UI incompatibility?

  • allanallan Posts: 63,180Questions: 1Answers: 10,411 Site admin

    iI don't see anything in the above that would cause a problem. Can you link to the page showing the problem so I can debug it please?

    Allan

  • semmelbroeselsemmelbroesel Posts: 8Questions: 1Answers: 0

    Thanks for your answer and confirming that my code is OK.

    Well, if it's not my code, then it's gotta be something else, likely jQuery or something...

    I don't have an easy way of sharing the page, but if experimenting with different versions of jQuery doesn't help, I'll see what I can do to upload the code somewhere.

    Thanks!

  • allanallan Posts: 63,180Questions: 1Answers: 10,411 Site admin

    That would be great - thanks.

    Allan

  • semmelbroeselsemmelbroesel Posts: 8Questions: 1Answers: 0

    FYI, I played around with different versions of jQuery and jQuery UI, and in the end, the one thing that fixed it all was upgrading dataTables from version 1.10.3 to 1.10.11. No idea why the old version works on one of my sites but not this one...

    But now all is working, and that's all that matters :-)

  • allanallan Posts: 63,180Questions: 1Answers: 10,411 Site admin

    Yup - using the latest version will always help. There was a bug in the early 1.10.x releases which caused errors with jQuery 1.11.3, but I wasn't aware of any issues with jQuery 1.9.

    Anyway, latest release is working, so all good news :-)

    Allan

  • stolstol Posts: 16Questions: 2Answers: 1

    I'm running the latest versions of Datatables (1.10.13), jquery(1.12.4) and jqueryui(1.12.1) and I'm having a similar problem. However, on the same site, one page works - I see the ajax call - and another page it doesn't.
    Any clues?

  • stolstol Posts: 16Questions: 2Answers: 1

    There was a mismatch with columns - I was initializing Datatables with 10 columns and only had 9 in the HTML!

This discussion has been closed.