I have made a loop in my JavaScript code and in that loop I use an XMLHttpRequest with a callback method but I'm having a problem with it.
When my loop ends the callback executes. This is not good, I need the callback to execute after calling a function, not after looping. How can I do this?
Somebody on a blog wrote that I can use an async method. How can I use an async method in this condition?
for (var i = 0; i < stuff.length; i++) {
var exist = IsstuffExist(stuff[i]);
alert(exist);
}
the called function show alert();
when i call function then i got alert of my code first and callback alert comes after my code.
how i can stop loop for sometime then i can get back response as callback from called function
if i use in looping
IsstuffExist(tags[i], function (result) {
if (result == true) {
$("#txtstuff").append(stuff[i]);
}