0

I have following code, when the button is clicked to load it gets array of data.

 $('#btnLoad').button().click(function () {
                    var ri = 110;
                 var data=  $.ajax({
                        type: 'Get',
                        url: "./app/test/sD?roodId=" + ri+"&",
                 });
                 alert(data[1].mainCo);                       
                    $('#tblAppendGrid').appendGrid('load', data)
                });

I can see in browser tools it returns array with set of values. However when I save it as data something is not right, cause in alert it just gives undefined error and thus does not load the grid. How can I save the returned array values so I can pass it to the grid. Thanks

J. Davidson
  • 3,297
  • 13
  • 54
  • 102
  • 1
    possible duplicate of [How to return the response from an AJAX call?](http://stackoverflow.com/questions/14220321/how-to-return-the-response-from-an-ajax-call) – Arun P Johny Oct 04 '13 at 08:54
  • For debug output you should use `console.log` instead of `alert`. – secelite Oct 04 '13 at 08:56

1 Answers1

2

$.ajax() returns a promise object, not the result of the ajax request, in order to handle the response of the request you need to use the callbacks provided by $.ajax()

You need to use callback

$('#btnLoad').button().click(function () {
    var ri = 110;
    $.ajax({
        type: 'Get',
        url: "./app/test/sD?roodId=" + ri + "&",
    }).done(function (data) {
        alert(data[1].mainCo);
        $('#tblAppendGrid').appendGrid('load', data)
    });
});

Read more about the ajax response handling here

Community
  • 1
  • 1
Arun P Johny
  • 384,651
  • 66
  • 527
  • 531