jqueryuiのドラッグアンドドロップコードを使用しています。ドロップすると、getJSONリクエストが実行され、新しいデータをチェックしてデータベースを更新します。匿名関数内からドロップをキャンセルできないため、バックエンドがエラーを返すまで、これは正常に機能します。
エラーが発生した場合、バックエンドは次のようなjsonを返します。
{"result":0}
ドロップを処理するコードは次のとおりです。
$('.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));
}});
これが少し明確であることを願っています。何か案は?:)