How to block on asynchronous functions in JavaScript

前端 未结 5 1767
臣服心动
臣服心动 2020-12-09 12:20

I need to write a function in JavaScript, which returns a state from calling an asynchronous function. However, the caller only receives the value and no callback function i

5条回答
  •  半阙折子戏
    2020-12-09 12:39

    Unless I misunderstood your question, you could look at jQuery's ajaxStop() event - http://api.jquery.com/ajaxstop. This blocks until all ajax calls have completed. This obviously requires that all of your async calls be done thru jQuery.

    $(document).ajaxStop(function() {
        // do your "ajax dependent" stuff here
    });
    

提交回复
热议问题