I am using jquery ui drag / drop code. A getJSON request on one drop is executed to check for new data and update the database. It works fine, as long as my backend did not return any errors, because I can not cancel the drop from within the anonymous function.
If there is an error, the backend returns to JSN which looks like this:
{"result": 0}
< P> This drop downing code: $ ('. Droppable'). Droppable ({drop: function} ($ .getJSON ('/ roster / save', 'location_id = 1', function () {if (data.result == 0) {// now cancel the drop But it can not be canceled with an anonymous function}}; // If the data was available here i get the result and cancel it if (data.result == 0) return false; // it will end // drop Drop ui.draggable.appendTo ($ ('ul', this));}});
I hope this is a bit obvious, any thoughts? :)
OK, until I found less ugly solution I found a synchronous Ajax JQuery .data Call in conjunction with the () method, therefore instead of .getJSON () call:
$. Data type: 'Jason', success: $. Proxy (data) {$ ($ (async: false, type: "post", url: "/ roster / add", data: 'location_id = 1' ). Data ('TMP', data)}, $ (this))}}
Then I can check the value of the data stored and if necessary I can return false:
if (this) .data ('tmp') results! = 1) {return false; }
Hope this helps someone.
Comments
Post a Comment