jQWidgets Forums

jQuery UI Widgets Forums Plugins Data Adapter issue with dataAdapter and ajax call

This topic contains 2 replies, has 2 voices, and was last updated by  Peter Stoev 9 years, 11 months ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
  • issue with dataAdapter and ajax call #72516

    Keshavan
    Participant

    Hi,

    I am unable to fetch data from dataAdapter even though my server side code is returning 2 records (json).
    success function is duly called but data.length is 0.
    Below is my code, pleas help what the issue is.

    Thanks,
    Keshavan

    `$(“#addressbutton”).click(function () {
    ctype = “hospital”;
    recordss = [];
    if (ctype != null || ctype != undefined || ctype != ” “) {
    $.ajax({
    id: ‘CustomerId’,
    async: false,
    dataType: ‘json’,
    url: ‘/Customer/GetCustomers?var=’ + ctype,
    type: ‘post’,
    data: {},
    success: function (data, status, xhr)
    {
    alert(data.length);
    },
    error: function (req, status, error)
    {
    alert(“R: ” + req + ” S: ” + status + ” E: ” + error);
    },
    complete: function (data) {
    recordss[0] = data[0];
    }
    })
    var source = recordss;
    var dataAdapterCustomer = new $.jqx.dataAdapter(source,
    {
    loadComplete: function ()
    {
    length = dataAdapterCustomer.records.length;
    alert(dataAdapterCustomer.records[0]);
    },
    formatData: function (data){
    $.extend(data, {
    recordss : data[0]
    });
    return data;
    },
    loadError: function (xhr, status, error) {
    alert(error);
    }
    });
    })`

    issue with dataAdapter and ajax call #72518

    Keshavan
    Participant

    Hi,

    here is formatted code.

    $(“#addressbutton”).click(function () {
     ctype = “hospital”;
    recordss = [];
     if (ctype != null || ctype != undefined || ctype != ” “) {
     $.ajax({
     id: ‘CustomerId’,
    async: false,
     dataType: ‘json’,
    url: ‘/Customer/GetCustomers?var=’ + ctype,
     type: ‘post’,
    data: {},
     success: function (data, status, xhr)
     {
     alert(data.length);
     },
     error: function (req, status, error)
     {
     alert(“R: ” + req + ” S: ” + status + ” E: ” + error);
     },
     complete: function (data) {
     recordss[0] = data[0];
     }
     })
     var source = recordss;
     var dataAdapterCustomer = new $.jqx.dataAdapter(source,
     {
     loadComplete: function ()
     {
     length = dataAdapterCustomer.records.length;
     alert(dataAdapterCustomer.records[0]);
     },
     formatData: function (data){
     $.extend(data, {
     recordss : data[0]
     });
     return data;
     },
     loadError: function (xhr, status, error) {
     alert(error);
     }
     });
     })
    issue with dataAdapter and ajax call #72520

    Peter Stoev
    Keymaster

    Hi Keshavan,

    I would suggest you to look at the Grid’s data binding demos, or the dataAdapter’s help topic. The dataAdapter in your code is not created correctly.

    Best Regards,
    Peter Stoev

    jQWidgets Team
    http://www.jqwidgets.com

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

You must be logged in to reply to this topic.