4

Something seems to be wrong, either my server response or my save function. In neither case success nor error function of model.save() gets invoked.

My server response:

exports.updateBusinessBannerAd = function(req, res) {
// update banner ad
db.insert(req.body, req.body._id, function(err, data) {
    if (err) {
        console.log('Update business banner ad: ' + err.message + '   ' + err['status-code']);
        res.send(err['status-code'], { header: 'Update banner ad', message: err.message, type: 'error'});
    }
    else {
        res.send(200);
    }
}); 

};

And here my client code:

saveBannerAd: function(self) {
        self.model.id = self.model.attributes._id; 
        self.model.save({
            success: function(model, res) {
                    utils.growl( 'Banner Ad', 'has been updated!', 'info');
                    self.resetHandler();
            },
            error: function(model, res) {
                console.log(res);
                utils.growl(res.header, res.message, res.type);
                return;
            }    
        }); 
    },

What am I missing?

bardu
  • 727
  • 2
  • 8
  • 24
  • I had same question when i was Backbone.js noob. Here is the answer http://stackoverflow.com/questions/9706260/getting-started-with-backbonejs-what-should-a-server-return – Deeptechtons Jul 19 '12 at 11:52

1 Answers1

1

Okay, adding { id: self.model.get('id') } as first argument to model.save() fixed my issue.

In this thread

someone suggested setting 'null' as first argument serves as placeholder, but my experience is that this will invoke the error function.

Community
  • 1
  • 1
bardu
  • 727
  • 2
  • 8
  • 24