Hi,
I'm using the jquery ui drag/drop code. Upon a drop a getJSON request gets executed to check the new data and update the database. This works fine, until my backend return an error, because I can't cancel the drop from within the anonymous function.
If there's an error the backend returns json that looks like this:
{"result":0}
This is the code handling the drop:
$('.droppable').droppable({
drop: function(event, ui) {
$.getJSON('/roster/save', 'location_id=1', function (){
if (data.result==0) {
// now the drop should be cancelled, but it cannot be cancelled from the anonymous function
}
});
// if data was available here I could check the result and cancel it
if (data.result==0)
return false; // this cancels the drop
// finish the drop
ui.draggable.appendTo($('ul', this));
}});
I hope this is a bit clear. Any ideas? :)