jQuery each() and multiple Ajax calls - elements in Ajax don't match parents in iteration
<p>I have an each() function that iterates across a number of tr elements, in reverse (lol).</p>

<pre><code>&lt;table&gt;
    &lt;tr&gt;&lt;th&gt;header row&lt;/th&gt;&lt;/tr&gt;
    &lt;tr&gt;&lt;td id="row1"&gt;row 1&lt;/td&gt;&lt;/tr&gt;
    &lt;tr&gt;&lt;td id="row2"&gt;row 2&lt;/td&gt;&lt;/tr&gt;
    &lt;tr&gt;&lt;td id="row3"&gt;row 3&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;

$($("table tr:gt(0)").get().reverse()).each(function() {
     tr=$(this);
     console.log(tr); // correctly prints my TRs in reverse order
}
</code></pre>

<p>Works great, but now watch:</p>

<pre><code>$($("table tr:gt(0)").get().reverse()).each(function() {
    tr=$(this);
    console.log(tr); // correctly prints my TRs in reverse order
    $.ajax({
         type: "POST",
         url: "ajax.php",
         data: data,
         dataType: "json",
         success: function(json) {
             console.log(tr); // incorrectly prints TRs in not-reverse order
             // TRs are not matched with above. Chaos ensues.
         }
    });
});
</code></pre>

<p>I figure what's happening is the Ajax call is taking longer to execute than the iteration over than the TR elements... I suppose I could set <code>async</code> to <code>false</code>, but <strong>is there a way to keep this asynchronous?</strong></p>

<p><strong>SOLUTION</strong></p>

<p>As @Nicola pointed out below, it's probably best to just send the  ID to the server along with the Ajax call and retrieve it again in the success function.</p>
