Server-side processing with SESSION check makes JSON error

Server-side processing with SESSION check makes JSON error

majodmajod Posts: 4Questions: 0Answers: 0
edited October 2012 in DataTables 1.9
Hello,

first of all I can't provide url for the website, because it's company development website with sensitive data.

I'm building a website with datatables table using server-side processing of the table. I'm using the default PHP code for the processing - just a bit modified for SESSION check on the top
http://www.datatables.net/development/server-side/php_mysql

+
session_start();
session_regenerate_id(true);
if(!isset($_SESSION['login']) || $_SESSION['UA'] != $_SERVER['HTTP_USER_AGENT'] || time() - $_SESSION['timeout']>=600){
session_unset();
session_destroy();
header('Location:index.php');
}else{
$_SESSION['timeout'] = time();

But what I noticed is when I'm using search provided by dataTables, sometimes when I type fast, I suddenly get an error:

DataTables warning (table id = 'example'): DataTables warning: JSON data from server could not be parsed. This is caused by a JSON formatting error

What I imagine is happing, that another request is made before SESSION check is completed and recieving incorrect data from the script. Am I assuming right? Is there any way how to deal with this problem?

Thank you very much.

Replies

  • allanallan Posts: 63,394Questions: 1Answers: 10,451 Site admin
    > DataTables warning (table id = 'example'): DataTables warning: JSON data from server could not be parsed. This is caused by a JSON formatting error

    Have a look at the JSON that is being returned from the server using Firebug / Inspector. Most likely you will see an error from your script and it will say what the problem is.

    Allan
  • majodmajod Posts: 4Questions: 0Answers: 0
    Thanks for the tip.

    I typed really fast and got lots of responses with 200 OK, but in the end i got "302 Moved temporarily".
    response from the script was 0B. The previous one was okay:
    {"sEcho":16,"iTotalRecords":"125","iTotalDisplayRecords":"0","aaData":[]}

    for the next Firebug just says
    Reload the page to get source for

    I can very easily simulate the same problem opening the web page on my phone, where after I try to search, dataTables prints "Processing..." for about a second. If I try to type another character within this second, I automatically get this JSON error.

    So I guess the same thing is happening on PC, but it's much faster and if I type faster than it processes the data, I won't pass the SESSION check.

    Is there any way or callback function to not allowing to type in search field while the script is processing server data?

    Thank you
  • allanallan Posts: 63,394Questions: 1Answers: 10,451 Site admin
    I'd suggest using this plug-in: http://datatables.net/plug-ins/api#fnSetFilteringDelay

    Allan
  • majodmajod Posts: 4Questions: 0Answers: 0
    Thank you very much, that seems to solve my problem so far :)
This discussion has been closed.