3

I have a simple Backbone model:

define(function(require) {

  var Backbone = require('backbone');

  var SessionModel = Backbone.Model.extend({
    url: 'http://stormy-ravine-2549.herokuapp.com/login',
    parse: function(data) {
      debugger;
    }
  });

  return SessionModel;
});

Here is my code where I am saving the model:

    var sessionModel = new SessionModel();
      sessionModel.set('username', $('#email').val());
      sessionModel.set('password', $('#password').val());
      sessionModel.save({
        success: function() {
          debugger;
        },
        error: function() {
          debugger;
        }
     });

I get a 200 response from the server with a json body of {"msg": "success"}. I hit the parse method in the model, but neither one of my callback functions get hit. Also, I am running my Chrome browser with CORS disabled. Doesn't either the success or errorcallback have to be hit?

jhamm
  • 24,124
  • 39
  • 105
  • 179

1 Answers1

2

You are telling backbone to only change the properties success and error. The second parameter is for options.

See Backbone model.save() not calling either error or success callbacks and also http://backbonejs.org/#Model-save

save accepts success and error callbacks in the options hash

Community
  • 1
  • 1
Prinzhorn
  • 22,120
  • 7
  • 61
  • 65