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

后端 未结 14 2329
暗喜
暗喜 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:59

    All of these answers miss the point that doing an Ajax call with async:false will cause the browser to hang until the Ajax request completes. Using a flow control library will solve this problem without hanging up the browser. Here is an example with Frame.js:

    beforecreate: function(node,targetNode,type,to) {
    
        Frame(function(next)){
    
            jQuery.get('http://example.com/catalog/create/', next);
        });
    
        Frame(function(next, response)){
    
            alert(response);
            next();
        });
    
        Frame.init();
    }
    

提交回复
热议问题