C# Jquery DataTables warning: JSON data from server could not be parsed.
C# Jquery DataTables warning: JSON data from server could not be parsed.
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
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
This discussion has been closed.
Replies
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
The other thing is, please do not post the same question multiple times. I've deleted the other thread.