If you use for, there is a situation where the execution of Ajax will be greater than the execution of other actions, then such a piece of code will not be implemented
for (Var i=0;i<20;i++) {
Console.log (' Hello ')
$.ajax (...)
}
What do we do?
Recursion, a lot of old programmers are doing this, so the code:
Currentindex = 0; functionAjax () {if(currentindex>=20) { return; } varURL =' URL '; Console.log (i); $.ajax ({type:' Get ', Url:url, DataType:"JSON", Async:false, Cache:true, Success:function(JSON) {Currentindex++; Console.log ("Test");Ajax (); }, Error:function(data) {Console.log ("Error ..."); Currentindex++; Ajax (); } }); }
Three major steps to solve the problem: 1. I want to, 2. Can't think of it, go online to find it, 3. Can't find, put the computer back to the system, and then submit the resignation, and then say goodbye to it. ^-^
Continue Ajax long polling solution-recursion