Error parsing JSON
Error parsing JSON
maheshnmurthi
Posts: 5Questions: 0Answers: 0
Hello,
I am using DataTables v1.7.5. I am using the Server Side processing to get data from the server. Farther below is the JSON that is returned by the server. But everytime I try to load the page I am getting:
DataTables warning: JSON data from server could not be parsed. This is caused by a JSON formatting error.
I tried searching in the forums and done the following:
a) looked into apache log records for some error which would lead me onto something
b) removed newline characters and carriage returns
c) used json_encode to encode the string before sending it back to the client.
d) b & c together.
But I am still stuck at the same place.
JSON from the Server:
[code]
{"sEcho": 1,
"iTotalRecords": 46,
"iTotalDisplayRecords": 10,
"aaData": [
["A Buffer Resource Allocation Problem", "", "BufferResourceAllocation.pdf", "" ],
["A Multimodal Function", "", "Multimodal.pdf", "multimodal.m" ],
["Ambulances in a square", "TextFileToGo.txt", "AmbulanceLocationsInSquare.pdf", "ambulance.m" ],
["Assemble to order", "", "AssembleToOrder.pdf", "Assemble_to_Order.m" ],
["Baby Call Center", "TextFileToGo.txt", "BabyCallCenter.pdf", "BabyCall.m" ],
["Bike Sharing in Fakeville", "BikeSharingReadme.txt", "BikeSharing.pdf", "BikeSharingData.csv" ],
["Booking limits at a hotel: Baby", "", "BABY HOTEL.pdf", "BabyHotel.m" ],
["Booking limits at a hotel: Full", "", "HOTEL FULL.pdf", "HotelFull.m" ],
["Container Freight", "", "ContainerExample.pdf", "ContainerFreight.m" ],
["Continuous Newsvendor", "TextFileToGo.txt", "ContinuousNewsvendor.pdf", "Newsvendor.m" ]
] }
[/code]
Any help is appreciated.
Thanks,
MNM
I am using DataTables v1.7.5. I am using the Server Side processing to get data from the server. Farther below is the JSON that is returned by the server. But everytime I try to load the page I am getting:
DataTables warning: JSON data from server could not be parsed. This is caused by a JSON formatting error.
I tried searching in the forums and done the following:
a) looked into apache log records for some error which would lead me onto something
b) removed newline characters and carriage returns
c) used json_encode to encode the string before sending it back to the client.
d) b & c together.
But I am still stuck at the same place.
JSON from the Server:
[code]
{"sEcho": 1,
"iTotalRecords": 46,
"iTotalDisplayRecords": 10,
"aaData": [
["A Buffer Resource Allocation Problem", "", "BufferResourceAllocation.pdf", "" ],
["A Multimodal Function", "", "Multimodal.pdf", "multimodal.m" ],
["Ambulances in a square", "TextFileToGo.txt", "AmbulanceLocationsInSquare.pdf", "ambulance.m" ],
["Assemble to order", "", "AssembleToOrder.pdf", "Assemble_to_Order.m" ],
["Baby Call Center", "TextFileToGo.txt", "BabyCallCenter.pdf", "BabyCall.m" ],
["Bike Sharing in Fakeville", "BikeSharingReadme.txt", "BikeSharing.pdf", "BikeSharingData.csv" ],
["Booking limits at a hotel: Baby", "", "BABY HOTEL.pdf", "BabyHotel.m" ],
["Booking limits at a hotel: Full", "", "HOTEL FULL.pdf", "HotelFull.m" ],
["Container Freight", "", "ContainerExample.pdf", "ContainerFreight.m" ],
["Continuous Newsvendor", "TextFileToGo.txt", "ContinuousNewsvendor.pdf", "Newsvendor.m" ]
] }
[/code]
Any help is appreciated.
Thanks,
MNM
This discussion has been closed.
Replies
One thing, although it won't result in the above error, is that iTotalDisplayRecords and iDisplayRecords should be the same unless you have a filter applied.
Allan
I have only added some new-line characters which I needed to make more sense when I was writing it to a file.
The other thing I did was to swap the single quotes for the double quotes in order to record the new line characters before writing to a file.
Seems like the example for server side has recently been enhanced and expanded. Should I give it a try before I get back?
Thanks,
Mahesh
Thanks for your valuable input. I am trying to implement it in a different fashion by styling the DOM and I build up the DOM using server side scripting. Do you think its a good idea? Also, could you send an example of this http://www.datatables.net/examples/server_side/row_details.html
I have not done extensive JavaScript or PHP programming, so it would be nice if you could send a working example so that I can learn how it has been done, both the PHP and JavaScript.
Also, could I use the demo_table.css file and modify it suitably? Thank you for your time.
Cheers,
Mahesh
I have done that example by building the DOM object using PHP script. My table size is just about 50 to 100 rows, so I don't think its a bad idea. Also, I am just wondering, in the example in hiding and showing details, could I do it with PHP only because I need to add links to files from the database.
Thanks,
Mahesh