How can I get jQuery to perform a synchronous, rather than asynchronous, Ajax request?

后端 未结 14 2332
暗喜
暗喜 2020-11-21 05:07

I have a JavaScript widget which provides standard extension points. One of them is the beforecreate function. It should return false to prevent an

14条回答
  •  遥遥无期
    2020-11-21 05:56

    You can put the jQuery's Ajax setup in synchronous mode by calling

    jQuery.ajaxSetup({async:false});
    

    And then perform your Ajax calls using jQuery.get( ... );

    Then just turning it on again once

    jQuery.ajaxSetup({async:true});
    

    I guess it works out the same thing as suggested by @Adam, but it might be helpful to someone that does want to reconfigure their jQuery.get() or jQuery.post() to the more elaborate jQuery.ajax() syntax.

提交回复
热议问题