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 6374833
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:32:16+00:00 2026-05-25T01:32:16+00:00

Using Backbone.JS, I am able to successfully create new models and save them to

  • 0

Using Backbone.JS, I am able to successfully create new models and save them to the server. They successfully make an ajax call and the subscribed UI elements update appropriately. The problem I then run into is that I don’t know the ID of the newly created object.

I can see in the response headers for my create calls, that the sever is returning a location header like: Location https://localhost/rest/beta/mobile/footer/OTo3Njow with the last parameter being the newly created ID.

How can I get this ID without overriding backbone.sync? If I have to override backbone.sync, what is the cleanest method?

UPDATE
It looks like my organization is using an older Backbone.js in which the parse method of models does not provide a reference to the XHR object, otherwise I could catch the ID and do the assigning there.

  • 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-25T01:32:17+00:00Added an answer on May 25, 2026 at 1:32 am

    The server should send back a JSON object containing the id of the model, plus any other attributes that it wants to update. If it does, Backbone will automatically grab the id.

    If that’s not an option, you should override Backbone.sync, because then your API (which communicates the new id in the location header instead of the response body) doesn’t conform to what Backbone supports out of the box.


    If the server already does this, and you just want to get at the id, it depends on who needs to know. If it’s the code calling model.save(), then it can pass in a success callback:

    model.save({}, {
        success: function(){
            // do something with model.id
        }
    });
    

    If the model itself needs to be notified when it gets an id, you can use an initializer:

    var MyModel = Backbone.Model.extend({
        initialize: function(){
            this.bind("change:id", function(){
                // …
            });
        }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We are using Backbone.js to build client-side UI that manipulates models shared by multiple
I want to create a tree table to display files using backbone.js + jQuery.
I'm using Devise and CanCan to create a backbone.js front-end and Rails 3.0.7 for
I am very new at using Backbone. Please forgive me in advance as I
This is my first attempt at using Backbone.js, so I decided to make a
I'm currently using Handlebars.js (associated with Backbone and jQuery) to make a web app
I'm using Backbone.js have a segmented control-type UI element for each model's view. They
I am using Rails + Backbone + Faye to make a sample chat application.
Im using backbone.js to get a collection from the REST server. Fetch triggers fine
I've just started using Backbone.js. I want to create a Collection and add some

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.