JQuery draggable callback called after sort from sortable
<p>I have a list of draggables connected to a list of sortables. The drag/drop works fine as does the sorting. The thing is that before the list gets sorted, I need to create a record in the DB (using rails). So I use $.post which works fine, but I need to change the the id of the inserted element. I do this by changing the id of the inserted element using the $.post callback. Works fine but it happens AFTER the sort. And if you're wondering why I didn't use the draggable stop callback it's because is does the same thing. Here's the abbreviated code (removed irrelevant db stuff):</p>

<pre><code>    $("#operations_container").sortable({items:'.process_small', axis:'y', update: function(ev,ui) {
 if (ui.item.attr('id').match("workcenter"))
 {
  $.post('/operations', 'fancyrailspoststuffignore', function(data) {
     $("#operations_container &gt; #workcenter_" + workcenterid).attr("id", "operation_" + data.operation.id);
     }, "json");
 } 
 $.post('/jobs/sort/&lt;%= @job.id %&gt;', 'morefancyschamncyrailsjunk);
}});
</code></pre>

<p>The sortable container is simple:</p>

<pre><code>&lt;div id="operations_container" class="in_grid"&gt;
&lt;/div&gt;
</code></pre>

<p>So it appears to me that all callbacks are called <em>after</em> the sort. Is this true? How do you get around this if you need to update the DOM before the sort? </p>

<p>UPDATE: In case they get missed in the comments, here are the image and sample files illustrating the problem.</p>

<p>Image : <a href="http://dl.getdropbox.com/u/1826667/sortable.png" rel="nofollow">http://dl.getdropbox.com/u/1826667/sortable.png</a>
Sample files: <a href="http://dl.getdropbox.com/u/1826667/jquery%5Fcallback%5Forder.zip" rel="nofollow">http://dl.getdropbox.com/u/1826667/jquery%5Fcallback%5Forder.zip</a></p>

<p>So it appears that the callbacks always end up at the end of any other events regardless of where they are called (@.post callback before sortable update is still called last, etc). I don't think it's a failing in JQuery (although I do find it odd); I AM trying to do a number of posts (which are required since they are co-dependent;create a record then sort) in the one go which is perhaps not the way to do it. I'll try and work around it in the backend (I have something almost working) so I'll consider this closed. Thanks to everyone who helped with the problem. SO rules.</p>

<p>MEGAIMPORTANTUPDATE: It's working! Shawn got it (see answer) and I'm still a bit giddy. It's been a few days on this thing. Thanks again to everyone and especially Shawn. You rock.</p>
