bServerSide=false w/ajax results in loss of sEcho, server-side errors/warnings

bServerSide=false w/ajax results in loss of sEcho, server-side errors/warnings

carteriiicarteriii Posts: 25Questions: 1Answers: 0
edited September 2010 in Bug reports
My situation can be reproduced using your server_site.html example. Simply change the bServerSide value to false and refresh the page.

You will notice that the table still loads w/ajax just fine, and now local searching also works just fine. However, this generates errors/warnings on the server because sEcho is no longer defined yet is accessed directly when setting $sOutput on line 147. By using Firebug I can see that all the "standard" parameters of dataTables are now missing in the call to server_processing.php.

It is great that we can still use ajax to return the data, yet perform local operations using bServerSide=false, but it seems that the code should still generate the proper information like sEcho when making the server request. I don't think this is urgent, but would you consider fixing that up in a future release?

Thank you.

Replies

  • allanallan Posts: 63,494Questions: 1Answers: 10,470 Site admin
    This isn't quite an expected interaction. When not using server-side processing, all you need to return is the array aaData, as shown in this example: http://datatables.net/examples/data_sources/ajax.html . There is no need to have the server do all of that processing, and it won't be sent any parameters by DataTables, so just a 2D array in aaData will do it.

    Allan
  • carteriiicarteriii Posts: 25Questions: 1Answers: 0
    Great. That would explain why it all works. I ended up in this situation only because I have been using true server-side processing for some complicated initial queries, but for some users the resultset was small so I wanted only local sorting & filtering (to avoid the server hits for every small search or sort). I guess I was either lazy or efficient and kept all the same server-side code, so I started to see the errors on sEcho. I've been able to put an isset() test around it, so I'm good.

    May I ask, what does sEcho do? I don't fully understand it, and the one documentation page (http://www.datatables.net/usage/server-side) just says it is for rendering.

    Thanks again.
  • allanallan Posts: 63,494Questions: 1Answers: 10,470 Site admin
    sEcho is basically a tracker for DataTables. Because of the asynchronous nature of the Ajax calls, it is actually possible for them to arrive out of sequence - it's unlikely, but certainly possible if you are rapidly changing pages for example. The sEcho variable allows DataTables to check what response it is expecting and what it has actually got - thus it can throw away old responses which have arrived after a later one!

    Making the XHR calls synchronous would address that issue - but hugely slow down the UI responsiveness (although it is possible to do if one wanted...).

    Allan
  • carteriiicarteriii Posts: 25Questions: 1Answers: 0
    That's very well thought out and implemented. Thanks for an awesome bit of work, and your responses here. I think I'll go hit your "Donate" button now, and I encourage everyone else reading this to do the same.
  • allanallan Posts: 63,494Questions: 1Answers: 10,470 Site admin
    Awesome - thanks :-). Great to hear that DataTables is proving to be useful!

    Allan
This discussion has been closed.