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

  • Home
  • SEARCH
  • 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 9288401
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T19:54:26+00:00 2026-06-18T19:54:26+00:00

I have a User model in a Backbone application that makes an ajax request.

  • 0

I have a User model in a Backbone application that makes an ajax request. In the error callback, I wish to set an error message to pass to the view. However, if I try do

this.set({errors: result.errors});

I’m told “this” doesn’t have a method set. In this case, I believe “this” is the ajax response object (rather than the User model which does have a set method)

Object {url: "/users.json", isLocal: false, global: true, type: "POST", contentType: "application/x-www-form-urlencoded; charset=UTF-8"…}

However, I also tried to do

  this.model.set({errors: result.errors});

but it said I can’t call “set” of undefined. I’m assuming it doesn’t make sense to say “this.model” from within the model, but, as mentioned above, if I just say “this,” it refers to the response object.

Is this the wrong way to go about it?

  • 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-06-18T19:54:28+00:00Added an answer on June 18, 2026 at 7:54 pm

    I am assuming you are doing something like this when you are saving your model

    model.save({
      success: function() {},
      error: function() {
        this.set({ errors: result.errors });
      }
    });
    

    If that is the case, then you can change this.set to model.set, and everything will work.

    However it doesn’t really make that much sense to be storing the error message as a model attribute.

    The model will fire an event when its save call fails on the server (check out the backbone events catalogue).

    Therefore if you have a view with an attached model, you can tell the view to listen to this error event.

    var MyView = Backbone.View.extend({
      initialize: function() {
        // if your using backbone v0.9.10
        this.listenTo(this.model, 'error', this.handleModelError);
        // or for earlier versions
        this.model.on('error', this.handleModelError, this);
      },
    
      handleModelError: function(model, xhr, options) {
        // show an error message, or whatever
      }
    
    });
    
    var view = new MyView({ model: aModel });
    
    // if the server returns an error, view.handleModelError will be called
    aModel.save();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a User model that has many posts. Im trying to render the
I have a user model on which I check to make sure that the
I have a user model that requires the user to change their password every
I have a User model that has the following default_scope: default_scope where(account_id: Account.current_account.id) If
I'm building an application in Backbone. In my collection model, I have a sync
I have a User model(Backbone.js) and I want to update its settings attribute and
I have the following model: var User = Backbone.Model.extend({ defaults: { status: this.constructor.status.OFFLINE, },
I have a collection of Backbone models like so: window.Message = Backbone.Model.extend({}); window.MessageCollect =
I have a multiselect dropdown that I'm rendering with Backbone. As user selects or
I have the following user model: var UserModel = Backbone.Model.extend({ urlRoot: 'user', defaults: {

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.