I’m using backbone.js to structure my client side app. Backbone.sync is working nicely for all the CRUD operations, however I’m unclear how to implement one of the server side requests I need to make. This request involves sending a model containing algorithm parameters to the server, and receiving a response containing the results of the algorithm (chart data points, tabular data etc). Calling model.save() doesn’t feel like the right thing to do, because backbone is expecting a response containing the updated model, whereas I would ideally like to create an entirely new model with the response.
Should I simply fall back to jQuery.ajax({data:model.toJson(),...}) and create a new model with the response? Or is there something else clever that I’m missing?
Many thanks.
What you want to do doesn’t sound like Create, Update, Read, or Destroy, it sounds more like an RPC call. There’s no reason to try to shoehorn a non-CRUD operation into a CRUD system like
Backbone.sync, you’re free to call$.ajaxyourself whenever it makes sense and an RPC-style call sounds like a good use for doing some manual AJAXing. Presumably you’d convert thesuccessresults into one or moresetcalls and let Backbone’s event system take it from there.