Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6643561
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:03:52+00:00 2026-05-26T00:03:52+00:00

My back-end has two separate pages, one for handling the model save request and

  • 0

My back-end has two separate pages, one for handling the model save request and the other for model fetch.

What is the best approach for calling save() and fetch() to use different URLs? Thanks.

Edit:
After studying the annotated source, I see that one can actually supply an options hash to fetch and save

//taken from backbone source:
save : function(attrs, options) {
  options || (options = {});
  if (attrs && !this.set(attrs, options)) return false;
  var model = this;
  var success = options.success;
  options.success = function(resp, status, xhr) {
    if (!model.set(model.parse(resp, xhr), options)) return false;
    if (success) success(model, resp, xhr);
  };
  options.error = wrapError(options.error, model, options);
  var method = this.isNew() ? 'create' : 'update';
  return (this.sync || Backbone.sync).call(this, method, this, options);
},

In the save, what purpose does the attrs serve? I’ve just been calling myModel.save() without passing anything in and it’s always been hashing my model’s attributes correctly. But now that I want to supply a ‘save url’ and I’m tempted to call

myModel.save(undefined, {
    url: 'myPath'
})

with the undefined required to ‘skip’ the first attrs paramter.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T00:03:53+00:00Added an answer on May 26, 2026 at 12:03 am

    If you’re reading the source you probably already have a working solution. You essentially have two options (probably more)-

    1. Pass URL in save()/fetch()

    save() takes two parameters attr and options
    attr – is a hash of model attributes and is used to update the model before save.
    eg.

    myModel.save(attrs)
    

    is equivalent to

    myModel.set(attrs)
    myModel.save()
    

    The second parameter is an options hash, which is passed down to this.sync() (and then Backbone.sync and then $.ajax) – setting the url in this hash will work as expected.
    You can pass false, undefined, or {} as the first parameter to skip the update.

    1. Override Backbone.sync

    Rather than have url’s scattered throughout your code every time you call save() or fetch() write your own sync function to compute the url for you, the delegate to the original Backbone.sync to do the heavy lifting

    eg. (This sync function adds /save to the url on CREATE, UPDATE and DELETE actions)

    function mySyncFunction(method, model, options){
      if(method=='GET'){
        options.url = model.url; 
      }else{
         options.url = model.url + '/save'; 
      }
      return Backbone.sync(method, model, options);
    }
    

    To use your custom sync method just declare it as part of your model

    var myModel = Backbone.Model.extend({ 
      ...
    
      "sync": mySyncFunction,
    
      ...
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The app my colleagues and I maintain has an Oracle database at the back-end.
A poorly-written back-end system we interface with is having trouble with handling the load
I have two tables X and Y . This is back end of a
I have two models generated with generate scaffolding, one is a LogBook the other
I have two related validations on separate models. I can validate one way but
My Android app has two location listeners, one for fine and one for coarse
I am going to develop a WCF service that connects back-end system with two
The back-end admin interface informs me that there is a new security patch for
I am using Java back end for creating an XML string which is passed
I have a java back-end that needs to expose services to clients running in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.