Hello. I have this code here (this is the structure of my code):
for (var x = 0; x < array1.length; x++){ (function(x) { $.ajax({ url : "http://someurl1.ru/"+array1[x]+"/", async: false, success : function(someresult1){ array2.length = 0; array3.length = 0; var br = someresult1.split('<br>'); for (var b = 0; b < br.length-1; b++){ var space = br[b].split(" "); array2.push(space[0]); array3.push(space[1]); } for (var v = 0; v < array2.length; v++){ (function(v) { $.ajax({ url : "http://someurl2.ru/"+array2[v]+"_"+array3[v]+"/", async: false, success : function(someresult2){ if(JSON.stringify(someresult2).search(some_array[x]) != -1){ $.ajax({ url : "http://someurl3.ru/"+array2[v]+"/"+array3[v]+"/"+some_another_array[x]+"", async: false, success : function(someresult3){ array4.push(someresult3); } }); } } }); })(v); } } }); })(x); } As you can see, he performs his task in the "forehead" (as written in my other question). This is truly so. And I have a question how to remake this code according to the mind? What I need is that all my ajax requests are executed in order. Now the whole structure is held by async: false. Without it, everything does not work correctly. And with him everything is pretty good, but the interface "hangs", well, it works quite slowly. Help improve this code. I laid out the structure of the code, and not the code itself, for a simpler understanding of my problem. As he in my understanding should work:
1. ΠΠ΅ΡΠ΅ΠΌ ΡΠ»Π΅ΠΌΠ΅Π½Ρ ΠΈΠ· 1 ΠΌΠ°ΡΡΠΈΠ²Π°. 2. Π€ΠΎΡΠΌΠΈΡΡΠ΅ΠΌ ΡΡΡΠ»ΠΊΡ ΠΈ ΠΎΡΠΏΡΠ°Π²Π»ΡΠ΅ΠΌ Π·Π°ΠΏΡΠΎΡ. 3. ΠΠΎΠ»ΡΡΠ°Π΅ΠΌ ΠΎΡΠ²Π΅Ρ ΠΈ Π΄Π΅Π»Π°Π΅ΠΌ Π½ΡΠΆΠ½ΡΠ΅ Π½Π°ΠΌ Π΄Π΅ΠΉΡΡΠ²ΠΈΡ (ΡΠ°Π·ΡΠ΅Π·Π°Π΅ΠΌ ΠΎΡΠ²Π΅Ρ ΠΈ Π·Π°Π³ΠΎΠ½ΡΠ΅ΠΌ Π² ΠΌΠ°ΡΡΠΈΠ²Ρ 2 ΠΈ 3). 4. Π€ΠΎΡΠΌΠΈΡΡΠ΅ΠΌ ΡΡΡΠ»ΠΊΡ ΠΈ ΠΎΡΠΏΡΠ°Π²Π»ΡΠ΅ΠΌ Π·Π°ΠΏΡΠΎΡ. 5. ΠΠΎΠ»ΡΡΠ°Π΅ΠΌ ΠΎΡΠ²Π΅Ρ ΠΈ Π΄Π΅Π»Π°Π΅ΠΌ Π½ΡΠΆΠ½ΡΠ΅ Π½Π°ΠΌ Π΄Π΅ΠΉΡΡΠ²ΠΈΡ (ΠΏΡΠΎΠ²Π΅ΡΡΠ΅ΠΌ ΡΠΎΠ²ΠΏΠ°Π΄Π΅Π½ΠΈΠ΅ ΠΎΡΠ²Π΅ΡΠ° Ρ ΡΠ»Π΅ΠΌΠ΅Π½ΡΠΎΠΌ Π² ΠΌΠ°ΡΡΠΈΠ²Π΅). 6. ΠΡΠ»ΠΈ Π΅ΡΡΡ ΡΠΎΠ²ΠΏΠ°Π΄Π΅Π½ΠΈΠ΅ ΡΠΎ ΡΠΎΡΠΌΠΈΡΡΠ΅ΠΌ ΡΡΡΠ»ΠΊΡ ΠΈ ΠΎΡΠΏΡΠ°Π²Π»ΡΠ΅ΠΌ Π·Π°ΠΏΡΠΎΡ. 7. ΠΠΎΠ»ΡΡΠ°Π΅ΠΌ ΠΎΡΠ²Π΅Ρ. 8. Π ΡΠΎΠ»ΡΠΊΠΎ ΡΠ΅ΠΏΠ΅ΡΡ Π±Π΅ΡΠ΅ΠΌ ΡΠ»Π΅Π΄ΡΡΡΠΈΠΉ ΡΠ»Π΅ΠΌΠ΅Π½Ρ ΠΈΠ· 1 ΠΌΠ°ΡΡΠΈΠ²Π°. I read quite a lot of answers on similar questions. Instead of async: false and for loops, it is suggested to use the recursive function call from the success and jquery promise callbacks. But it is offered everywhere where they used either queries in a cycle, or you need to execute queries in turn. But I have a situation when I want to execute requests in turn (and what would they wait for each other) and it is still in the loop (+ I have requests embedded in each other). So help the experts.