× {{alert.msg}} Never ask again
Get notified about new tutorials RECEIVE NEW TUTORIALS

Backbone: Saving an entire collection to non-RESTful server

Yuriy Linnyk
Apr 06, 2016
<p>You don't have to force yourself to use <code>sync</code> if it doesn't help you. <code>sync</code> is there to save you time in common scenarios.</p> <p>As you can see in the <a href="http://backbonejs.org/docs/backbone.html#section-169">annotated <code>sync</code> code</a>, it eventually just calls <a href="http://api.jquery.com/jquery.ajax/">jQuery.ajax</a> and includes logic to help with RESTful backends. </p> <p>Also it triggers some events, which you might or might not listen in other parts of your app, like <code>request</code> (when the request was made) and <code>sync</code> (when the request was successfully completed), or <code>error</code> (if the request failed)</p> <p>All of these you can do from your app, if reinventing <code>sync</code> isn't exciting.</p> <p>Prepare your data, call <a href="http://api.jquery.com/jquery.ajax/"><code>$.ajax</code></a> to send the data to your backend, and optionally <a href="http://backbonejs.org/#Events-trigger"><code>trigger</code></a> the backbone events, if you're going to listen to them.</p> <p>This tip was originally posted on <a href="http://stackoverflow.com/questions/33135228/Backbone:%20Saving%20an%20entire%20collection%20to%20non-RESTful%20server/33247328">Stack Overflow</a>.</p>
comments powered by Disqus