Getting Error : Json data from server could not be parsed. This is caused by JSON formatting error.
Getting Error : Json data from server could not be parsed. This is caused by JSON formatting error.
rajneeshkmr
Posts: 3Questions: 0Answers: 0
Hi ,
I am using SQL server 2005 at my BackEnd and trying to retrieve data from server in the form of JSON. i validated the JSON and it's Valid. When i paste the JSON in file and try to access it, it's working fine.
Please find Below the code.
$(document).ready(function () {
// $.fn.dataTableExt.sErrMode = 'throw';
$('#testTable').dataTable({ "sPaginationType": "full_numbers", "bJQueryUI": true, "bProcessing": true, "bServerSide": true,
// "sAjaxSource": "/SupportApp/1.txt",
"sAjaxSource": "/SupportApp/Default.aspx/FetchFOIDetails",
"aoColumns": [
{ "mData": "ServiceOrderNo" },
{ "mData": "PcodeDesc" },
{ "mData": "Action" },
{ "mData": "Status" }
],
},
"error": function () { alert('error'); }
});
Server side code is :
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json, UseHttpGet = false, XmlSerializeString = true)]
//public static string FetchFOIDetails(string TaskID)
public static string FetchFOIDetails()
{
string str = "{\"aaData\" : [{\"ServiceOrderNo\":\"511121336727696846-3\",\"PcodeDesc\":\"Configure Admin Account in AccMan\",\"Action\":\"Cease\",\"Status\":\"CLOSE\"},{\"ServiceOrderNo\":\"511121336727696862-3\",\"PcodeDesc\":\"Configure Admin Account in AccMan for Toolkit\",\"Action\":\"Cease\",\"Status\":\"CLOSE\"},{\"ServiceOrderNo\":\"511121336727696866-8\",\"PcodeDesc\":\"Configure Admin Account in AccMan for Toolkit Access\",\"Action\":\"Cease\",\"Status\":\"CLOSE\"}]}";
return str;
}
Please help me!!!
I am using SQL server 2005 at my BackEnd and trying to retrieve data from server in the form of JSON. i validated the JSON and it's Valid. When i paste the JSON in file and try to access it, it's working fine.
Please find Below the code.
$(document).ready(function () {
// $.fn.dataTableExt.sErrMode = 'throw';
$('#testTable').dataTable({ "sPaginationType": "full_numbers", "bJQueryUI": true, "bProcessing": true, "bServerSide": true,
// "sAjaxSource": "/SupportApp/1.txt",
"sAjaxSource": "/SupportApp/Default.aspx/FetchFOIDetails",
"aoColumns": [
{ "mData": "ServiceOrderNo" },
{ "mData": "PcodeDesc" },
{ "mData": "Action" },
{ "mData": "Status" }
],
},
"error": function () { alert('error'); }
});
Server side code is :
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json, UseHttpGet = false, XmlSerializeString = true)]
//public static string FetchFOIDetails(string TaskID)
public static string FetchFOIDetails()
{
string str = "{\"aaData\" : [{\"ServiceOrderNo\":\"511121336727696846-3\",\"PcodeDesc\":\"Configure Admin Account in AccMan\",\"Action\":\"Cease\",\"Status\":\"CLOSE\"},{\"ServiceOrderNo\":\"511121336727696862-3\",\"PcodeDesc\":\"Configure Admin Account in AccMan for Toolkit\",\"Action\":\"Cease\",\"Status\":\"CLOSE\"},{\"ServiceOrderNo\":\"511121336727696866-8\",\"PcodeDesc\":\"Configure Admin Account in AccMan for Toolkit Access\",\"Action\":\"Cease\",\"Status\":\"CLOSE\"}]}";
return str;
}
Please help me!!!
This discussion has been closed.
Replies
Also please link a test case in future: http://datatables.net/forums/discussion/12899/post-test-cases-when-asking-for-help-please-read
Allan
Thanks for your quick response.
Please find below the test case:
$(document).ready(function () {
// $.fn.dataTableExt.sErrMode = 'throw';
$('#testTable').dataTable({ "sPaginationType": "full_numbers", "bJQueryUI": true, "bProcessing": true, "bServerSide": true,
// "sAjaxSource": "/SupportApp/1.txt",
"sAjaxSource": "/SupportApp/Default.aspx/FetchFOIDetails",
"error": function () { alert('error'); },
"aoColumns": [
{ "mData": "ServiceOrderNo" },
{ "mData": "PcodeDesc" },
{ "mData": "Action" },
{ "mData": "Status" }
]}
);
$("#testTable tbody").delegate("tr", "click", function () {
var firstCellText = $("td:first", this).text();
var fourthCellText = $("td:eq(3)", this).text();
alert(firstCellText + " " + fourthCellText);
});
});
I also validated my JSON on http://jsonlint.com and it's valid .
The JSON is :
{"aaData" : [{"ServiceOrderNo":"511121336727696846-3","PcodeDesc":"Configure Admin Account in AccMan","Action":"Cease","Status":"CLOSE"},{"ServiceOrderNo":"511121336727696862-3","PcodeDesc":"Configure Admin Account in AccMan for Toolkit","Action":"Cease","Status":"CLOSE"},{"ServiceOrderNo":"511121336727696866-8","PcodeDesc":"Configure Admin Account in AccMan for Toolkit Access","Action":"Cease","Status":"CLOSE"}]}
i put the breakpoint on serverside method, but it's not hitting the breakpoint.
Can you please suggest me ??
Allan
Thanks for your response again. i was able to trace the issue.
"contentType": "application/json; charset=utf-8" was missing in my AJAX call. i am able to get a call for the method now.
But ,oncre the JSON is returned, i am getting error "Microsoft JScript runtime error: Unable to get value of the property 'length': object is null or undefined" in jquery.datatables.js.
My JSON Response is as follows:
{"iTotalRecords":6,"iTotalDisplayRecords":6 ,"aaData" : [{"ServiceOrderNo":"IBTAAICIADS25558880-11","PcodeDesc":"Confirm Order Closure for ADS","Action":"Provide","Status":"CLOSE"},{"ServiceOrderNo":"IBTAAICIApmo25558880-13","PcodeDesc":"Confirm Order Closure (AIntl-APMo)","Action":"Provide","Status":"CLOSE"},{"ServiceOrderNo":"IBTAAICIEB25558880-11","PcodeDesc":"Confirm Order Closure for Web Analysis Base (CAS)","Action":"Provide","Status":"CLOSE"},{"ServiceOrderNo":"IBTAAICIUD25558880-11","PcodeDesc":"Confirm Order Closure for Unified Dashboard (VSM)","Action":"Provide","Status":"CLOSE"},{"ServiceOrderNo":"IBTAAICIVB25558880-7","PcodeDesc":"Confirm Order Closure for Vantage Base","Action":"Provide","Status":"CLOSE"},{"ServiceOrderNo":"IBTAAICIWA25558880-11","PcodeDesc":"Confirm Order Closure for Web Analysis (CAS)","Action":"Provide","Status":"CLOSE"}]}
Can you please help me OR atleast suggest, where should i look for ?
I have googled alot , but not finding any convincing solution.
I am able to read the data ,when i keep data in file and i can't replicate it, as the JSON is being returned from Webmethod.
I have checked JSON on http://pro.jsonlint.com/ and it's valid.
Allan