JSON Data NOT Valid

JSON Data NOT Valid

benpeterbenpeter Posts: 14Questions: 5Answers: 0

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

  • allanallan Posts: 63,691Questions: 1Answers: 10,500 Site admin

    DataTables can read that format just fine. Use the columns.data option and ajax.dataSrc (set to be a space). See also the data manual.

    Allan

  • benpeterbenpeter Posts: 14Questions: 5Answers: 0

    allan: Thank you for your support, but i dont understand your response please.

  • benpeterbenpeter Posts: 14Questions: 5Answers: 0

    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

  • allanallan Posts: 63,691Questions: 1Answers: 10,500 Site admin

    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

  • benpeterbenpeter Posts: 14Questions: 5Answers: 0
    edited December 2014

    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

  • allanallan Posts: 63,691Questions: 1Answers: 10,500 Site admin

    Thanks for the debug trace - I see the same error there as you reported before, regarding "Message": "Invalid JSON primitive: draw.".

    You are currently POSTing the data to userDetails.aspx/getJSONData". Is it expecting POST? Is it able to read the draw 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

  • benpeterbenpeter Posts: 14Questions: 5Answers: 0

    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.

  • allanallan Posts: 63,691Questions: 1Answers: 10,500 Site admin

    I dont know how it is supposed to expect a post

    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

This discussion has been closed.