Invalid JSON alert, JSON data is valid

Invalid JSON alert, JSON data is valid

EricEric Posts: 24Questions: 0Answers: 0
edited August 2010 in General
Ugh, this is frustrating. I'm passing JSON data back using server side processing.

I'm getting the "json data from server failed to load or be parsed" message. I'm returning this data from a Java Servlet. My content type is defined as "application/json" and I also tried x-json.

Here's the valid json:

[code]
{
"sEcho":1,
"iTotalRecords":1,
"iTotalDisplayRecords":1,
"aaData":[
["TAA","Create ProgramTAA","ActiveTAA","Waiting OnTAA","OwnerTAA","When CreatedTAA","When StartedTAA","When EndedTAA","Next DeliveryTAA","InstructionsTAA"]
]
}
[/code]

And I'm implementing it like so:

[code]
$('#viewTableTest').dataTable({
"iDisplayLength": 25,
"aLengthMenu": [[25, 50, 100, -1], [25, 50, 100, "All"]],
"bStateSave": true,
"bServerSide": true,
"sAjaxSource": "../tasks/manage.jsp?_response=true&_action=filterTasks"
});
[/code]

Any ideas?

Replies

  • EricEric Posts: 24Questions: 0Answers: 0
    Nevermind, I figured it out.
  • gabrieldcgabrieldc Posts: 3Questions: 0Answers: 0
    Hi I have the same problem, I made a servlet for processing on the server and when I load the page I get a message saying "DataTables warning: JSON data from server failed to load or Be parsed." I would like to know how you solved the problem... thanks
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Have a look at this FAQ, it should help: http://datatables.net/faqs#json

    Allan
  • EricEric Posts: 24Questions: 0Answers: 0
    My problem was that not just the json data was being returned, but the code in my jsp was being attached to it somehow. In the code above, my source had "tasks/manage.jsp", but when I put in an alert I could see the json data AND the code of the jsp. I have a blank.jsp (empty file) that I use to call my servlet filters so I used that instead and it worked. I'm not really sure why that when you use write data to the response that the jsp code is always included, so the project I'm working on used a blank.jsp for those situations and I just followed suit.
  • gabrieldcgabrieldc Posts: 3Questions: 0Answers: 0
    solved the problem, I had an error in the servlet, it throws an exception .. thanks
  • gabrieldcgabrieldc Posts: 3Questions: 0Answers: 0
    DataTable is fabulous
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    :-)

    Good to hear you got it sorted.

    Allan
This discussion has been closed.