how to wait for an ajax call to return

前端 未结 6 890
天涯浪人
天涯浪人 2021-01-12 20:00

I\'m trying to use JQuery although i\'m struggling to successfully wait for a ajax call to succeed before executing further code. Is there a way to wait for an ajax to call

6条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-12 20:59

    Have a look at jQuery deferreds. You can't halt this, but you can call other code after an AJAX call returns.

    // No way to stop.
    $.ajax(...);
    doSomething();
    

    But with deferds you can:

    $.ajax(...).success(function() {
       doSomething();
    });
    

    See this article.

    http://www.erichynds.com/jquery/using-deferreds-in-jquery/

提交回复
热议问题