Use jquery to perform serial execution on multiple AJAX requests.
HTML code:
<a href= "#" >click me!</a>
Js:
function Getsomedeferredstuff () {
var deferreds = [];
var i = 1;
for (i = 1; I <= 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 () {
$ ("a"). Click (function () {
var deferreds = Getsomedeferredstuff ();
$.when.apply (null, deferreds). Done (function () {
$ ("div"). Append ("<p>all done!</p>");});
The method is similar to Q in Node.js, using the Promise defer mode to put all AJAX requests into an array and then through $.when.apply (). Done () executes all AJAX requests sequentially.
The above is a small set of jquery to introduce the use of Deferreds serial multiple Ajax request, I hope to help you, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!