0

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 1

1

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"; 
  }
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.