javascript - How JQuery Ajax works? -


i trying send data jquery ajax generic handler calculates , returns result. ajax request made inside for loop @ jquery end. code looks this:

function send(handler, ids) {     var url = "http://" + window.location.host + "/handlers/" + handler + ".ashx";     var i;     (i = 0; < 10; i++) {         var cur = $('.' + ids[i]);         $.ajax({             url: url,             type: "post",             data: json.stringify({                 data: cur             }),             datatype: "json",             cache: false,             beforesend: //my before send code,             success: //my success code,             error: //my error code         });     }     alert('done!'); } 

i placed 3 breakpoint in visual studio 2012 @ line:

$.ajax({ 

this

alert('done!'); 

and third breakpoint @ first line in generic handler.

now, when try execute code, ajax works nicely in async way. but, when reaches first breakpoint, stops there , resume it, instead of reaching generic handler's breakpoint, continues loop , goes first breakpoint. after reaches second breakpoint stops @ generic handler's break point again , again each value.

so, mean ajax first collects ajax requests , after for loop executes them together?

javascript single threaded , non-blocking. means in first iteration won't wait ajax call completed, go , start second iteration, , on. so, no doesn't executes them together. definately starts ajax calls in order of loop there no way tell end first. might make ajax calls , answer (doesn't mean answer of first iteration), or in middle of loop might getting answers.


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - Bypass Geo Redirect for specific directories -

php - .htaccess mod_rewrite for dynamic url which has domain names -