I have a Ajax webmethod that needs to populate a JQuery table. The code i have produces no errors, but I don't see any data in my table.
Here is the WebMethod:
here is the JSON Data being returned:
This is currently being sent to a basic table like this :
the end results are :
Can someone point in the direction as to why no data is being shown please?
* EDIT *
Here is the method code which creates the JSON data. This is being called by the WebMethod, which returns a string
try
{
rdr = cmd.ExecuteReader();
if (rdr.HasRows)
{
using (JsonWriter jsonwriter = new JsonTextWriter(sw))
{
jsonwriter.WriteStartArray();
int totalrecords = 0;
while (rdr.Read())
{
jsonwriter.WriteStartObject();
int fields = rdr.FieldCount;
for (int i = 0; i < fields; i++)
{
jsonwriter.WritePropertyName(rdr.GetName(i));
jsonwriter.WriteValue(rdr[i]);
}
jsonwriter.WriteEndObject();
totalrecords++;
}
jsonwriter.WriteEndArray();
}
}
Here is hte WebMethod:
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public static string ApprovalInfo(string messageId)
{
string json = string.Empty;
json = GetComments(messageId);
return json;
}
* EDIT * I've installed and run the DataTables debug program, which produces the following:
"sAjaxDataProp": "[{\"UserName\":\"watherton\",\"EnteredDate\":\"2013-07-18T14:36:46.387
\",\"Comment\":\"some comment 2\"},{\"UserName\":\"watherton\",\"EnteredDate\":\"2013-07-
18T16:12:41.753\",\"Comment\":\"some comment 3\"}]",
"aoColumns": [{
"mDataProp": "UserName"
}, {
"mDataProp": "EnteredDate"
}, {
"mDataProp": "Comment"
}]
this doesn't look right to me. I've done a debug in Firebug, and the above stream of data is being returned in the response tab, the JSON tab looks different. So, i guess someplace I need to tell the WebMethod/AJax call to use the JSON not the response. perhaps?