DataTables seems to be trying to parse JSON object before it has been sent from server.

DataTables seems to be trying to parse JSON object before it has been sent from server.

GregNGregN Posts: 4Questions: 0Answers: 0
edited January 2013 in General
I'm working on a dashboard for internal use at my company and am experiencing what I think is a timing issue with the data retrieval for the dataTables that I'm creating in the dashboard.

Here's the background ... I am loading three tables, one per jQueryUI tab. The data is coming from some rather large databases, one in excess of 200,000 records, therefore I'm using a server-side set up. Trouble is, the client-side seems to be trying to parse JSON objects before they are actually sent over from the server.

When I load the website, I first get the "DataTables warning: JSON data from server could not be parsed" message. At this point, firebug shows a response to the call as:

[quote]Reload the page to get source for: http://wshq-dwes01/test/grnelson/sbox/tools/pvsettings/branchData?sEcho=1&iColumns=25&sColumns=&iDisplayStart=0&iDisplayLength=50&mDataProp_0=0&mDataProp_1=1&mDataProp_2=2&mDataProp_3=3&mDataProp_4=4&mDataProp_5=5&mDataProp_6=6&mDataProp_7=7&mDataProp_8=8&mDataProp_9=9&mDataProp_10=10&mDataProp_11=11&mDataProp_12=12&mDataProp_13=13&mDataProp_14=14&mDataProp_15=15&mDataProp_16=16&mDataProp_17=17&mDataProp_18=18&mDataProp_19=19&mDataProp_20=20&mDataProp_21=21&mDataProp_22=22&mDataProp_23=23&mDataProp_24=24&sSearch=&bRegex=false&sSearch_0=&bRegex_0=false&bSearchable_0=true& ... etc. [/quote]


I click "OK" on the pop-up and I get the header of the table and the "Processing" message. If I click one of the tabs housing the tables, it seems to jump start the processing again and the table gets correctly populated with the data. Now firebug shows a reapons that is actually a JSON object:

[quote] {"sEcho":"3","iTotalRecords":440,"iTotalDisplayRecords":50,"aaData":[["1110","8240","8200","Y","N","N","NOBLOCK","N","NORMAL","N","Y","Y","N","N","Y","N","N","Y","7302","Y","0.99","N","000001","1","\"devnull@wesco.com,devnul"],["1114","8520","8500","Y","N","Y","NOBLOCK","N","NORMAL","N","Y","Y","N","N","Y","N","N","Y","7302","Y","0.99","N","000001","1","\"UTILITYPRICING@WESCO.com"],["1116","8240","8200","Y","N","Y","NOBLOCK","Y","MARKET_DISPLAY","Y","Y","Y","N","N","Y","N","N","Y","7302","Y","0.99","Y","000001","2","\"PRICING_NE@WESCO.com,dev"],["1120","8520","8500","Y","N","Y","NOBLOCK","N","NORMAL","N","Y","Y","N","N","Y","N","N","Y","7302","Y","0.99","N","000001","1","\"UTILITYPRICING@WESCO.com"],["1219","8240","8200","Y","N","Y","NOBLOCK","Y","MARKET_DISPLAY","Y","Y","Y","N","N","Y","N","N","N","7302","Y","0.99","Y","000001","2","\"devnull@wesco.com,devnul"],["1225","8960","8900","Y","N","N","N","N","NORMAL","N","Y","Y","N","N","Y","N","N","N","7302","Y","0.00","N","000001","1","\"devnull@wesco.com,devnul"],["1231","8960","8900","Y","N","N","N","N","NORMAL","N","Y","Y","N","N","Y","N","N","N","7302","Y","0.99","N","000001","1","\"devnull@wesco.com,devnul"],["1232","8520","8500","Y","N","Y","NOBLOCK","N","NORMAL","N","Y","Y","N","N","Y","N","N","Y","7302","Y","0.99","N","000001","1","\"UTILITYPRICING@WESCO.com" ... etc. [/quote]

Similarly, when entering a keyword in the "Search:" entry field, the warning message will pop up before I've finished keying in the keyword. When close the pop-up, one of two things happens. Either I am allowed to finish keying in my search text and the filtering happens as expected or I can key in whatever I like, but nothing will happen, the search functionality falls completely apart.

Unfortunately, you will not be able to access the site as it not available from outside the company's intranet. I've run DataTables Debug and the generated code is "amiyet". The server-side is implemented in cakephp. I'll be happy to share with you whatever code you would like to see, but it really seems to be working, except for being a bit impatient.

So ... any suggestions?

Replies

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    Very odd - the JSON looks valid, but that warning comes from jQuery's parser. Could you run the debugger immediately after clicking okay from the error alert?

    Allan
  • GregNGregN Posts: 4Questions: 0Answers: 0
    Well - I ran the debugger immediately after clicking the okay button on the error alert, the code for the results is "asusil", but I don't know that it will do much good. The debugger just "spun" until the data had loaded anyway. I think I'm going to have to set some breakpoints in the jQuery script and start stepping through it in the hopes that I can zero in on something.

    If you have any better I ideas, I would appreciate your help.
  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    > asusil

    Good stuff - thanks for that. If you load http://debug.datatables.net/asusil and click on the 'Tables' tab and then 'Server interaction' for the first table - you'll see that it is not responding with JSON - hence the error. It is in fact responding with an XHTML document (from http://wshq-dwes01/test/grnelson/sbox/tools/pvsettings/branchData ).

    The other two tables do have a JSON response from the server.

    Allan
  • GregNGregN Posts: 4Questions: 0Answers: 0
    First of all, thanks, Allan. I think you've been able to point me in the right direction. I recognize the page that is initially being returned as the user login page for the development environment that I'm working in. I'm checking with the powers that be to see if, as I suspect, some recent changes in the system are the source of the trouble. I'll let you know.
  • GregNGregN Posts: 4Questions: 0Answers: 0
    Ok. There were two issues that I needed to address - neither of which really had anything to do with the dataTables code. They were issues with the way I had architected the various pieces of the puzzle that set me up with something of a recursive call of the web site. Chalk it up to inexperience, I guess.

    Anyway, I do want to thank you again for pointing me in the right direction and, much more so, thank you for this excellent tool.
  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    Good to hear that you found and fixed the issue. Thanks for the feedback :-)

    Allan
This discussion has been closed.