How can I write an async method in JavaScript when posting or looping?
<p>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.</p>

<p>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?</p>

<p>Somebody on a blog wrote that I can use an async method. How can I use an async method in this condition?</p>

<pre><code>for (var i = 0; i &lt; stuff.length; i++) {
                        var exist = IsstuffExist(stuff[i]);
                        alert(exist);
                    }
</code></pre>

<p>the called function show alert();</p>

<p>when i call function then i got alert of my code first and callback alert comes after my code.</p>

<p>how i can stop loop for sometime then i can get back response as callback from called function</p>

<p>if i use in looping </p>

<pre><code> IsstuffExist(tags[i], function (result) {
                            if (result == true) {
                                $("#txtstuff").append(stuff[i]);
                            }
</code></pre>
