Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Backbone model.save() not hitting success/error callback? [duplicate]

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?

like image 819
jhamm Avatar asked Jun 27 '26 03:06

jhamm


1 Answers

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

like image 142
Prinzhorn Avatar answered Jun 28 '26 15:06

Prinzhorn



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!