Double AJAX call appends data to datatables rather than overwrite it.

Double AJAX call appends data to datatables rather than overwrite it.

metateckmetateck Posts: 10Questions: 0Answers: 0
edited September 2013 in Bug reports
Test Case: http://api-dev.pigeonly-api.com/admin/inmate-search?sex=&first_name=john&last_name=miller

This page makes 2 AJAX requests on load. The first is just with an empty form (this happens upon datatables initialization), and the second happens only if there are GET parameters. It will simply resubmit the form if there are GET parameters. Since this AJAX call happens second, I expect the second AJAX call response to overwrite the first AJAX call response in datatables. Instead, you get appended data.

The AJAX file being called has a hardcoded limit of 500 records in its response. In the test case, you will get around 560 records. If you hit search from the test case with the params, the AJAX will be called a 3rd time and this time will get only the 60 records. If you go to the test case without the GET params, then you will get 500 records.

Replies

  • allanallan Posts: 63,680Questions: 1Answers: 10,498 Site admin
    I'm on an iPad atm, so can't really debug this just now, but I'll have a look when I get back to a desktop.

    Allan
  • metateckmetateck Posts: 10Questions: 0Answers: 0
    Did you ever get a chance to look at this?
  • allanallan Posts: 63,680Questions: 1Answers: 10,498 Site admin
    Could you try moving your code which checks for the GET parameters and then issues a submit (and therefore a fnReloadAjax) into the DataTables fnInitComplete callback option please? I'm wondering if the fnReloadAjax plug-in is having an async issue. I suspect that if the second ajax call ( fnReloadAjax ) returns before the first, then the data probably will be added as duplicate, as DataTables isn't expecting other data in the background. fnReloadAjax should probably cancel the existing Ajax request if there is one.

    Allan
  • metateckmetateck Posts: 10Questions: 0Answers: 0
    Thank you very much. This resolved the issue.
This discussion has been closed.