How to load html table in asp.net not mvc ? my data comes wrong format

How to load html table in asp.net not mvc ? my data comes wrong format

Syed Babar AliSyed Babar Ali Posts: 9Questions: 4Answers: 0

HTML TABLE

  1. 2. 3. 4. 5. 6. 7. 8. 9.
    ABC

Data Format Comes from server side debug mode data

Object {d: "{"Table":[["1235876sfwer",100.00,"\/Date(147560760…76sfwer",100.00,"\/Date(1475521200000)\/"],null]}"}d: "{"Table":[["1235876sfwer",100.00,"\/Date(1475607600000)\/"],["1235876sfwer",100.00,"\/Date(1475521200000)\/"],null]}"proto: Object

Javascript Syntax

$.ajax({
type: "POST",
dataType: "json",
contentType: 'application/json; charset=utf-8',
url: '/WebForm1.aspx/GetQueryInfo',
success: function (dataa) {
debugger
$('#example').DataTable({
data: dataa
});
}
});

This question has an accepted answers - jump to answer

Answers

  • bindridbindrid Posts: 730Questions: 0Answers: 119
    edited May 2017

    soooo

    $.ajax({
    type: "POST",
    dataType: "json",
    contentType: 'application/json; charset=utf-8',
    url: '/WebForm1.aspx/GetQueryInfo',
    success: function (dataa) {
    debugger
    $('#example').DataTable({
    data: JSON.parse(dataa.d);
    });
    }
    });
    
  • bindridbindrid Posts: 730Questions: 0Answers: 119

    My guess is that you are doing something like

    [WebMethod]
    [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
    public static string yourfunctionname (int itemId, string quantity)
    {
    // bunch of code left out

    JavaScriptSerializer serializer = new JavaScriptSerializer();
    return serializer.serialize(yourobject);
    }

    So:
    If your issue is the date format, that is a valid format. You can use something like moment.js plugin to covert that format into a proper date. Or add readonly product that converts the date to a string on the server. Or, what I do, use newtonSoft (its a better serizlizer anyway). It lets you set the format of the date

  • bindridbindrid Posts: 730Questions: 0Answers: 119
    Answer ✓

    As for the other issue, Ajax will deserialize the data sent back by the server. The problem is that in the above configuration, the data is actually being serialized twice, once by you, once by the web service itself. A web service can return an object without you serializing it first. Something like this:

    [WebMethod]
    [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
    public static YourObject yourfunctionname (int itemId, string quantity)
    {
    // bunch of code left out
        return YourObject
    }
    

    Your data would still come back in the d object (that's Microsoft) but it would be fully serialized

  • Syed Babar AliSyed Babar Ali Posts: 9Questions: 4Answers: 0

    Thanks

This discussion has been closed.