I have a drag&drop functionality in my web app. As the user releases the mouse after a drag&drop, the position of the object is saved to the server using Backbone's save() method on the model. When the server responds, it triggers a set() on the model with the returned properties. However, in the time the server was processing the request, the user might already have again dragged the object to a different position. This causes problems as the response from the server will now override the settings of the object in the browser.
Is there a way to prevent Backbone from doing the set() after it gets the response from the server after the save()?
Had similar use case while doing a system before albeit that was more trouble hence we needed to really override the models set()
function. Although for this case a couple of relatively easier ways are available.
You can override the model parse() function. Or you can call an abort()
on the jqXHR object returned by the save()
call.
http://api.jquery.com/jQuery.ajax/#jqXHR
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With