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

2

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.