Pausing For Loop jQuery question
<p>I have an issue with javascript/jQuery...I have a web service that will process information from a list from the client. What I want to do is have the client send the data piece by piece allowing the web service to do its job without being overloaded. Also I am using a jQuery UI progressbar which will allow the user to see the progress of their request. </p>

<p>My problem is that I am using a for loop and when the loop runs it seems that the loop runs to completion so if there are 10 pieces of data to process, all ten runs simultaneously...</p>

<p>What I'm asking is there a way to make the for loop pause until a success message is received from the server?</p>

<p>This is what I tried:</p>

<pre><code>var nums = [1,2,3,4,5,6,7,8,9,10];

        for (var i in nums) {

        //I also tried 
        //for (num = 1; num &lt;= 9; num++) {

            //start loop
            $("#progressbar").progressbar('option', 'value', num);
            var input = {
                "num": num,
                "total": 100
            }

            //  .progressbar('option', 'value', 37);              
            var jsonStr = JSON.stringify(input);
            //d = '{' + d + '}';
            $.ajax({
                type: "POST",
                url: "AjaxWcf.svc/TestModal",
                contentType: "application/json; charset=utf-8",
                data: jsonStr,
                dataType: "json",
                success: function(msg) {
                    $("#progressbar").progressbar({
                        value: num
                    });

                    //alert(msg.d);
                    //                    jQuery('#modalContentTest.loading').fadeOut(200);
                    //                    setTimeout('jQuery.modal.close()', 1000);

                    $("#message").value = msg;
                },
                error: AjaxFailed
            });
        }

        function AjaxFailed(result) {
            alert(result.status + ' ' + result.statusText);
        }
    });
</code></pre>

<p>I know its late so maybe I'm crosseyed and maybe some sleep will help me see this from a different angle, buuuuuttt if someone could help with this or show me an alternetive, I'd appreciate it.</p>

<p>Thanks!!!</p>
