I'm working with Backbone.js, and have a collection of models. The RESTful service I'm integrating with requires me to add a "r=true" parameter to the URL to get a JSON representation of the model in the response (which is needed to get the id back during a POST). Is there a way to add that parameter to the URL when POST or PUT is done when I call model.save()?
1 Answer
You can use http://api.jquery.com/jQuery.ajaxPrefilter/ with something like:
$.ajaxPrefilter( function( options ) {
// check if the method is PUT or POST
// check if there is no parameter, add ?r=true, otherwise add &r=true
options.url = options.url + "&r=true";
}
});