Strange troubles with sEcho
Strange troubles with sEcho
Hi,
first of all - thanks - I've hacked something like this recently, but this looks awesome!
Anyway, I'm quite new to jquery and I've been playing with DataTables for a single day, but I had some strange problems with the 'server-side data' example - no matter what I did the table remained empty and a message 'processing' was displayed. I've actually downloaded the page and used exactly the same data, but still it did not work - I've seen the data are downloaded (thanks to the access log) but it was not displayed.
In the end I've debugged the script and I've noticed that it 'fails' thanks to line 2758 (in the _fnAjaxUpdateDraw function):
if ( json.sEcho*1 < oSettings.iServerDraw )
{
return;
}
because the data contain "sEcho = 0" and the iServerDraw = 1, the function silently returns. Once I removed the sEcho from the data, it works. So I have two questions:
1) What is sEcho supposed to do? I guess it's a way to prevent stale / cached data, right?
2) Why does it work for you (on your site), but once I download it it does not work anymore?
Thanks
first of all - thanks - I've hacked something like this recently, but this looks awesome!
Anyway, I'm quite new to jquery and I've been playing with DataTables for a single day, but I had some strange problems with the 'server-side data' example - no matter what I did the table remained empty and a message 'processing' was displayed. I've actually downloaded the page and used exactly the same data, but still it did not work - I've seen the data are downloaded (thanks to the access log) but it was not displayed.
In the end I've debugged the script and I've noticed that it 'fails' thanks to line 2758 (in the _fnAjaxUpdateDraw function):
if ( json.sEcho*1 < oSettings.iServerDraw )
{
return;
}
because the data contain "sEcho = 0" and the iServerDraw = 1, the function silently returns. Once I removed the sEcho from the data, it works. So I have two questions:
1) What is sEcho supposed to do? I guess it's a way to prevent stale / cached data, right?
2) Why does it work for you (on your site), but once I download it it does not work anymore?
Thanks
This discussion has been closed.
Replies
2. The most common cause is that JSON return from the server is not valid. If you put the return through http://jsonlint.com - is it valid? The next most common reason is that sEcho is not being returned exactly as it was sent (although cast as an 'int' on the server-side). Either of these apply?
Allan
And I think this explains why the 'copy' of the example does not work - I have used a static copy of the data, i.e. I've downloaded the data from http://www.datatables.net/examples/examples_support/server_processing.php and stored them in a text file. But this way there is no 'sEcho' value in the request so the 'static' data contain just 'sEcho':0 and do not reflect the value from the AJAX requests (made when loading the data by the table). Now it's clear.
Anyway the only explanation of 'sEcho' (purpose and how it works) I've found is located at http://www.datatables.net/usage/server-side and I think it's unsufficient. For new developers (e.g. me) this may be very confusing so I'd recommend to put there a clear description that the request has to contain the 'sEcho' value sent in the request (or no 'sEcho' at all), and I'd put the same notice to the "DataTables server-side processing example" page too.
Good to hear that did the trick for you :-). What I've done to hopefully address this a little bit in future is to tidy up the server-side usage page a bit to note the use sEcho a little bit more: http://www.datatables.net/usage/server-side . I've also added this as an FAQ: "Its still not working..." http://datatables.net/faqs . Hopefully this will help others in future, along with this thread.
Regards,
Allan