Why do I get a different array?
<p>Good day.
I have  problem with give different arrays;</p>

<p>my code next:</p>

<pre><code>setInterval(function() {

var TestName = [];
var requests = [];
TestName.push('0');
for($i=1; $i&lt;8; $i++) {
    var id = $i;
    requests.push($.post("./Scripts/", {
    record:id,
    opt:'get_test'
    }, function(data){
          TestName.push(data);
    }));
}

 $.when.apply($,requests).done(function(){

     for($i=1; $i&lt;8; $i++) {
$('#test'+$i).html('').html(TestName[$i]);

}
alert(TestName);
 });

}, 15000);
</code></pre>

<p>This code works but every time I get different arrays...</p>

<p>For example:</p>

<p><code>alert(TestName);</code> <strong>result one:</strong></p>

<pre><code>0,
&lt;a href="#"&gt;&lt;img src="./images/test1.png"&gt;&lt;/a&gt;,
&lt;a href="#"&gt;&lt;img src="./images/test2.png"&gt;&lt;/a&gt;,
&lt;a href="#"&gt;&lt;img src="./images/test3.png"&gt;&lt;/a&gt;,
&lt;a href="#"&gt;&lt;img src="./images/test4.png"&gt;&lt;/a&gt;,
&lt;a href="#"&gt;&lt;img src="./images/test5.png"&gt;&lt;/a&gt;,
&lt;a href="TestTestTestTestTest.php"&gt;&lt;img src="./1358997710.jpg"&gt;&lt;/a&gt;,
&lt;a href="#"&gt;&lt;img src="./images/test7.png"&gt;&lt;/a&gt;,
</code></pre>

<p><code>alert(TestName);</code> <strong>result two:</strong></p>

<pre><code>0,
&lt;a href="#"&gt;&lt;img src="./images/test1.png"&gt;&lt;/a&gt;,
&lt;a href="#"&gt;&lt;img src="./images/test2.png"&gt;&lt;/a&gt;,
&lt;a href="TestTestTestTestTest.php"&gt;&lt;img src="./1358997710.jpg"&gt;&lt;/a&gt;,
&lt;a href="#"&gt;&lt;img src="./images/test3.png"&gt;&lt;/a&gt;,
&lt;a href="#"&gt;&lt;img src="./images/test5.png"&gt;&lt;/a&gt;,
&lt;a href="#"&gt;&lt;img src="./images/test4.png"&gt;&lt;/a&gt;,
&lt;a href="#"&gt;&lt;img src="./images/test7.png"&gt;&lt;/a&gt;
</code></pre>

<p>As you can see elements of the array each time exchange seats, and sometimes elements of the array are arranged in the wrong order.</p>

<p>Tell me please where may be been error in code?</p>
