Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Backbone save without set on callback

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()?

like image 832
Bjorn Avatar asked Aug 21 '13 16:08

Bjorn


1 Answers

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

like image 190
Anthony Chua Avatar answered Oct 30 '22 08:10

Anthony Chua