dafi dafi - 7 months ago 44
jQuery Question

JQuery UI sortable: restore position based on some condition

I call

to make an ajax call to store some data after drag & drop operation.

When the ajax call returns an error (application logic error or net problem) I want to move the dragged element to its original/start position, how can I achieve it?

The scenario should be

  1. user drags A to B

  2. the
    event is called, it triggers an ajax call

  3. the ajax call returns an error

  4. inside the
    event we get the ajax error

  5. move A to its original position

  6. user again move A to B

  7. everything is ok

  8. A remains in its new position in B

Steps 6-8 are shown to clarify a successive drag can be done and previous error must be forgotten.


Have a look at .sortable('cancel'); something like this:

var list = $('#some-list')
    // Some options.
    stop: function()
        $.post('some-url', someData, function()
            if (somethingWentWrong)