backbonejs' alteration of ajax handler parameters
As I spend time learning Backbone I've found some unexpected things (to me probably not to others). Today I found that even though Backbone fetch allows you to pass in typical jQuery ajax options (like success or error handlers), it will alter what parameters are passed back to those handlers.
Here is an example of plain jane ajax call (in older style jQuery before renaming of events):
Here is an example of backbone success handler:
The one really nice part of the different parameters is that backbone gives you objects instead of raw-ish data. This means if you need to create two different models (or collections) from the same call, you can pass it directly into the model 'set' method. (see line 13).
Now the question is the best way to handle a situation where the backend server returns multiple models in a response. In this case, I chose to pull them out in a custom ajax handler and update one collection to use specific part of the return data. But I could have been persuaded to create custom ajax call to retrieve and then create each model/collection separately. This might be a good place to write out some examples, code snippets and write about what I learn. I suspect that it will vary like most things :)
__END__
In jQuery
In backbone handler
In backbone fetch changes up what you receive. It is nicely stated in that section:The options hash takes success and error callbacks which will both be passed (collection, response, options) as arguments.I only read that like 3 times before i actually saw that note :)
Here is an example of backbone success handler:
The one really nice part of the different parameters is that backbone gives you objects instead of raw-ish data. This means if you need to create two different models (or collections) from the same call, you can pass it directly into the model 'set' method. (see line 13).
Now the question is the best way to handle a situation where the backend server returns multiple models in a response. In this case, I chose to pull them out in a custom ajax handler and update one collection to use specific part of the return data. But I could have been persuaded to create custom ajax call to retrieve and then create each model/collection separately. This might be a good place to write out some examples, code snippets and write about what I learn. I suspect that it will vary like most things :)
__END__
Great & Useful Articles
ReplyDeleteBackbone.js Course | Backbone.js Training | Backbone.JS Online Course | Backbone.JS Training in Chennai
Great Article
DeleteCloud Computing Projects
Networking Projects
Final Year Projects for CSE
JavaScript Training in Chennai
JavaScript Training in Chennai
The Angular Training covers a wide range of topics including Components, Angular Directives, Angular Services, Pipes, security fundamentals, Routing, and Angular programmability. The new Angular TRaining will lay the foundation you need to specialise in Single Page Application developer. Angular Training
Nice Post. To get study abroad in any course. For students who is looking for study medicine in abroad, we will help with end to end services with zero cost.
ReplyDeleteSkolarrssolutions
Mbbs in Russia
Mbbs in UK
Mbbs in Malaysia
I was looking fot this ajax handler finally found it here thanks for sharing
ReplyDeletehttps://mulazmut.com/kp-government-jobs/
Beayer Strain Theory
ReplyDeleteSasche Mohr Theory
Pressure difference b/w two point
Preservation of pharmaceutical products
Materials for plant construction
Flow of fluid
Drug synergism and antagonism
Thixotropy/ Measurement of Viscosity/ Instruments
Pharmacodynamic-General introduction