jQWidgets Forums

jQuery UI Widgets Forums Grid unable to map JSON response from server to grid – plz help

Tagged: , , ,

This topic contains 1 reply, has 2 voices, and was last updated by  Peter Stoev 12 years ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author

  • suhail
    Member

    Hi,

    I am trying to get simple JSON data from ASP.NET webservice which returns simple data with 2 fields user and description, but unfortunately i am not able to send data and recieve response from server. my code is as below

    ———————————————————————————————————–

    $(document).ready(function () {
    var loadGrid = function () {
    $.ajax({
    type: “POST”,
    url: “http://NB3101007850/TestService/Service1.asmx/GetAll”,
    data: “{}”,
    contentType: “application/json; charset=utf-8”,
    dataType: “json”,
    beforeSend: function () {
    $(“jqxgrid”).html(”);
    },
    error: function (json, textStatus, errorThrown) {
    alert(‘ Error :’ + errorThrown);
    },
    success: function (data) {
    // initailize grid
    var gridData = data;
    var gridSource =
    {
    localdata: gridData,
    datatype: ‘json’
    };
    var gridDataAdapter = new $.jqx.dataAdapter(gridSource);
    $(“#jqxgrid”).jqxGrid(
    {
    width: 670,
    source: gridDataAdapter,
    editable: true,
    pageable: true,
    autoheight: true,
    selectionmode: ‘singlecell’,
    columns: [
    { text: ‘User’, datafield: ‘User’, width: 250 },
    { text: ‘Description’, datafield: ‘Description’, minwidth: 120 }
    ]
    });
    }
    });
    }
    loadGrid();
    $(“#Button”).click(function () {
    loadGrid();
    });
    });

    ———————————————————————————————————————-

    my http request should contain

    POST /TestService/Service1.asmx/GetAll HTTP/1.1
    Accept: application/json, text/javascript, */*
    Accept-Language: en-us
    x-requested-with: XMLHttpRequest
    Content-Type: application/json; charset=utf-8
    Accept-Encoding: gzip, deflate
    User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)
    Host: nb3101007850
    Content-Length: 2
    Connection: Keep-Alive
    Cache-Control: no-cache

    my http response will be

    HTTP/1.1 200 OK
    Cache-Control: private, max-age=0
    Content-Type: application/json; charset=utf-8
    Server: Microsoft-IIS/7.5
    X-AspNet-Version: 2.0.50727
    X-Powered-By: ASP.NET
    Date: Tue, 30 Apr 2013 17:03:58 GMT
    Content-Length: 299

    [truncated] {“d”:”[{\”User\”:\”Suhail\”,\”Description\”:\”Test1\”},{\”User\”:\”Sabeel\”,\”Description\”:\”Test2\”},{\”User\”:\”Sarwar\”,\”Description\”:\”Test2\”},{\”User\”:\”Fathima\”,\”Description\”:\”Test2\”},{\”User\”:\”Fathima\”,\”Description\”:\”Test5\”},{\”User\”:\”Ismail\”,\”Description\”:\”Test6\”}]”}

    ———————————————————————————————————

    i want to display this information in grid.

    Please let me know if i am doing any mistake. your immediate help will be highly appreciated as i need to prove to management that JQWidgets can be suitable platform for our project.

    regards


    Peter Stoev
    Keymaster

    Hi,

    Have you tried var gridData = data.d;?

    Best Regards,
    Peter Stoev

    jQWidgets Team
    http://www.jqwidgets.com/

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.