How to Force a Backbone Model to "Save" Synchronously

in , February 14th, 2025
Note: I do not recommend saving model’s synchronously unless you have to. It is rare for this to be a best practice solution.

Documentation for Backbone model.save() function: Backbone.js

Code to Force a Backbone Model to "Save" Synchronously

The Backbone “save” function on Models runs asynchronously by default. There may be times when you want this call to run synchronously. See the code block below for the required parameter in that case.

let model = new Backbone.Model();


model.save({ test: "test"}, { async: false });


model.get('test') // this equals test and will not run until the save is complete
NOTE: “async” MUST be passed in the second argument for it to be read as an argument of the function rather than an attribute on the model.

Author: Sam Gagliardi


FREE SuiteCommerce Book

If you liked this article, you'll LOVE our book on SuiteCommerce! Order the free SuiteCommerce book today, and we'll even pay for shipping!

Oracle NetSuite Alliance Partner & Commerce Partner

If you have general questions about SuiteCommerce or more specific questions about how our team can support your business as you implement NetSuite or SuiteCommerce, feel free to contact us anytime. Anchor Group is a certified Oracle NetSuite Alliance Partner and Commerce Partner equipped to handle all kinds of NetSuite and SuiteCommerce projects, large or small!

We are a premium SuiteCommerce agency that creates powerful customer portals. Unlike our competitors, we have already solved your problems.

 
 

Want to keep learning?

Our team of NetSuite and ecommerce professionals has written articles on a wide variety of topics, from step-by-step tutorials, to solution recommendations, available support services, and more!

Your cart