JQuery uses deferreds to serial multiple ajax requests, jquerydeferreds
Use JQuery to perform serial execution on multiple ajax requests.
HTML code:
<A href = "#"> Click me! </A> <div> </div>
JS:
Function GetSomeDeferredStuff () {var deferreds = []; var I = 1; for (I = 1; I <= 10; I ++) {var count = I; deferreds. push ($. post ('/echo/html/', {html: "<p> Task #" + count + "complete. ", delay: count }). success (function (data) {$ ("div "). append (data) ;}) ;}return deferreds ;}$ (function () {$ (""). click (function () {var deferreds = GetSomeDeferredStuff (); $. when. apply (null, deferreds ). done (functi On () {$ ("div"). append ("<p> All done! </P> ");});});});
The method is similar to Node. q in js, put all ajax requests in an Array Using promise defer mode, and then use $. when. apply (). done () executes all ajax requests in sequence.