C# Jquery DataTables warning: JSON data from server could not be parsed.

C# Jquery DataTables warning: JSON data from server could not be parsed.

sanrocsanroc Posts: 2Questions: 0Answers: 0
edited July 2013 in General
Hi All,
I was getting this
"DataTables warning (table id = 'tblClients'): DataTables warning: JSON data from server could not be parsed. This is caused by a JSON formatting error." On loading a page itself. Can any one please tell me where am I doing wrong??

Here is my code:

In my aspx page:




$(document).ready(function () {
$("#tblClients").dataTable({
"sPaginationType": "full_numbers",
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "Default.aspx/GetData",
"sServerMethod": "POST"
});
});



ID
First Name
Middle name
Age
Gender








In codebehind C# :

[WebMethod(EnableSession=true),ScriptMethod]
public static DataTableResults doSearch(string sEcho, string sSearch, int iDisplayStart, double iDisplayLength, int iSortingCols, int[] iSortColsArray, string[] sSortDirArray)
{
DataTableResults dtResults = new DataTableResults();
List personDetails = new List();
PersonDetails pDetail = null;
for (int i = 0; i < 5; i++)
{
pDetail = new PersonDetails();
pDetail.ID = i;
pDetail.Age = i + 20;
pDetail.FirstName = "FirstName_" + i;
pDetail.MiddleName = "MiddleName_" + i;
if (i % 2 == 0)
{
pDetail.Gender = "Male";
}
else
{
pDetail.Gender = "Female";
}
personDetails.Add(pDetail);
}

dtResults.iTotalRecords = personDetails.Count;
dtResults.iTotalDisplayRecords = personDetails.Count;
dtResults.sEcho = sEcho;
dtResults.aaData = personDetails.ToArray();
return dtResults;
}

public class DataTableResults
{
public string sEcho { get; set; }
public int iTotalRecords { get; set; }
public int iTotalDisplayRecords { get; set; }
public object[] aaData { get; set; }
}

public class PersonDetails
{
public int ID;
public string FirstName;
public string MiddleName;
public int Age;
public string Gender;
}

Can any one please help me?? Thanks in Advance

Replies

  • allanallan Posts: 63,516Questions: 1Answers: 10,472 Site admin
    PLease link to a test case or use the debugger: http://datatables.net/forums/discussion/12899/post-test-cases-when-asking-for-help-please-read
  • sanrocsanroc Posts: 2Questions: 0Answers: 0
    Hi allan,

    Thanks for you quick reply. I couldn't able to find the solution from the link dude!!!
    Help me how to get the data from c# code behind method using the datatables will be much appreciated.

    Thanks,
    Sanroc
  • allanallan Posts: 63,516Questions: 1Answers: 10,472 Site admin
    edited July 2013
    Did you read the post I linked to? It notes the forum rules of how you need to link to a test case so we can actually offer some help :-)

    The other thing is, please do not post the same question multiple times. I've deleted the other thread.
This discussion has been closed.