开发者

How to execute a command after an AJAX call?

I wrote this script:

$.getJSON('<%=Url.Action("JsonSave","Controler")%>', {
    id: newR开发者_如何学Cow.Id,
    personId: newRow.PesronId},
    function(data) {
        $('#grid').trigger('reloadGrid'); //{0}
        $('#grid').editRow(rowCount); //{1}
    })
})

What should I do so that {1} would be executed exactly after {0}?


ANSWER UPDATED I did a little research, and it seems you are using the jQuery Grid plugin. It has a callback called gridComplete that should do what you need. Combine that with my original answer to use one and you will be all set:

Since events are called in order, you could add your method into the event queue like this:

$.getJSON('<%=Url.Action("JsonSave","Controler")%>',
        { id: newRow.Id, personId: newRow.PesronId},
         function(data) {
            $('#grid').one('gridComplete', function(){ $('#grid').editRow(rowCount); });
            $('#grid').trigger('reloadGrid');
         })

Using the one instead of bind causes your event callback to be used only once.


Doug's answer is right except the event to be used is loadComplete

jQGrid documentation for events


Are trigger() and editRow() asynchronous calls? If so, you may be out of luck doing it this way, as you don't know when they will be called.

If you need editRow() to be called after trigger() completes, make the call to EditRow() at the end of the trigger() function itself.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜