JQuery $ .when and $. then unexpected results

I use $.when().then() to process functions in a specific order. Everything works as expected, but if the when function requires a lot of DOM manipulation or a relatively slow ajax request, the function in then is executed until when completed. I duplicated the results on JSFiddle:

http://jsfiddle.net/7ZSrv/3/

run_last should be executed last, but as you can see, it is not. Do I ever use it wrong in this case? Any help would be appreciated!

+4
source share
1 answer
 $.when( $.get('/', process1), $.get('/', process2), $.get('/', process3)) .then(function(){ $.get('/echo/html', run_last); }); 

fixes the problem. You passed the directly executed $.get request to then , and not the callback that will trigger the receive request.

+6
source

Source: https://habr.com/ru/post/1397687/


All Articles