Assuming you corrected the syntax errors in your code (missing $
before .ajax
, missing "
on url
value, and missing closing });
on the $.ajax
call, plus any other errors I didn't spot):
$(document).ready(function () {
$('.out').each(function(index) {
$.ajax({
url: "php",
type: "GET",
success: function(data) {
// LOOP each dynamic textbox for my specific validation
console.log('1'); // flag if any error
}
});
});
console.log('2'); // my plan is to check if atleast 1 error occur
});
Then the order the statements within your ready function will be executed is first the .each()
will call $.ajax()
for each of the '.out'
elements, then the console.log('2')
at the end will be executed and the ready function will complete, then later the success function will be called for each Ajax request in the order the Ajax responses are received by the browser - which isn't necessarily the same order the Ajax requests were made. (Obviously this assumes they actually are successful.)
This is because Ajax requests are (supposed to be) asynchronous - the response callbacks will always be called after the current block of code finishes, regardless of how fast the response is received, because (ignoring web workers) JavaScript is not multi-threaded.