JSON Data NOT Valid
JSON Data NOT Valid
After executing my Web Method in an aspx page and serializing it, i get the following output:
[{"UserID":"U001 ","UserName":"kakaa ","StaffID":"140P120C ","CPOFLogin":"Yes","FirstLogin":"\/Date(1392152400000)\/","LastLogin":"\/Date(1392152400000)\/","UserStatus":"Online "},{"UserID":"U002 ","UserName":"kokuu ","StaffID":"2D01P23 ","CPOFLogin":"No ","FirstLogin":"\/Date(1407790800000)\/","LastLogin":"\/Date(1407790800000)\/","UserStatus":"Offline "}]
what is it that i am supposed to do so that it gets a formal dataTable structire
Answers
DataTables can read that format just fine. Use the
columns.data
option andajax.dataSrc
(set to be a space). See also the data manual.Allan
allan: Thank you for your support, but i dont understand your response please.
When i try to use as adviced, i get the following error:
Invalid JSON primitive draw:
ExceptionType: "System.ArgumentException"
Message: "Invalid JSON primitive: draw."
StackTrace: " at System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializePrimitiveObject()
↵ at System.Web.Script.Serialization.JavaScript
That looks like a server-side error. Is your server process returning the JSON you posted above or not? It sounds like it might not be. Also
draw
is a server-side processing parameter. Are you using server-side processing? Do you need to (are you using 50k+ rows)?Allan
Thank you allan. When i trap the return value by the WebMethod function in the code-behind, that is what i get. When i try to check the data returned by ajax using success property as
"success": function(data){alert(data.d)},
i get nothing. The error above is generated instead.
Kindly help.
I also used datatable debugger bookmarklet and in return gave me the support code oxukat. Kindly help
Thanks for the debug trace - I see the same error there as you reported before, regarding
"Message": "Invalid JSON primitive: draw."
.You are currently
POST
ing the data touserDetails.aspx/getJSONData"
. Is it expecting POST? Is it able to read thedraw
parameter?Without being able to see the server-side code, there is really very little help I can offer, as it is a server-side issue, not one in the DataTables client-side library.
Allan
Thank you for your response allan. Yes my intention is to make an ajax POST request to execute a webmethod getJSONData in the userDetails.aspx page. I dont know how it is supposed to expect a post. Am a novice here! OK. Thank you let me see what might be the problem there.
It would probably be worth checking out a .NET forum. In Web API I know you can use the
[HttpPost]
decorator, but there are so many different ways of doing these things in .NET that I'm not aware of them all (a bit new at .NET myself!).Allan