Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I make a sync call with backbone fetch

I need to call a fetch with a synchronous call, I know with jquery ajax I can use {async: false} can I pass this option to fetch function ?

like image 329
Petran Avatar asked Aug 26 '13 16:08

Petran


People also ask

How does Backbone JS work?

Backbone. js gives structure to web applications by providing models with key-value binding and custom events, collections with a rich API of enumerable functions, views with declarative event handling, and connects it all to your existing API over a RESTful JSON interface.

Which function has to be used when you want to trigger the event only once before being removed?

js Event once() The event once method is just like event on method but it causes the bound callback to only fire once before being removed.

Does backbone need jQuery?

You can use the Backbone. Model without jQuery, but Backbone.


2 Answers

So the short answer is yes, you can simple call fetch function with param

{async:false}.
like image 127
Petran Avatar answered Sep 19 '22 22:09

Petran


Actually backbone fetch method internally calls ajax. So you can pass any ajax options to backbone fetch method.

collection.fetch({
  // ajax options
   async: false, // by default it is true
   success: function(collection, response, options){
             console.log("success")
          },
   error: function(collection, response, options){
             console.log("error")            
          }
});
like image 43
ni3 Avatar answered Sep 21 '22 22:09

ni3