AlexW.H.B.
AlexW.H.B.

Reputation: 1871

model.save setting the url and making a call back on success

I'm trying to get this method to work:

that.model.save(null,  // I'm calling that.model because this is nested in another method
{
   url: 'some url',

    success: function(model, response) {
        // update stuff
    }, 
    error: function(model, response) {
        // throw error. 
    }
}); 

but for some reason it does not call the success method or the error method. where the comments are I I'm calling methods... I don't want to get into the specifics of all the methods I'm calling. also the save method works, it just does not call eater of those methods.

also if i try and just call a method that I alrady made like:

success: that.somemethod()

javascript throws: Uncaught TypeError: Illegal invocation

any help would be greatly appreciated.

Upvotes: 0

Views: 90

Answers (2)

Ocean
Ocean

Reputation: 2942

First, you must bind instance method and then assign it to success

that.model.save(null,  // I'm calling that.model because this is nested in another method
{
    url: 'some url',

    success: _.bind(that.mySuccessMethod, that), 
    error:   _.bind(that.myErrorMethod, that)
}); 

Upvotes: 1

c4urself
c4urself

Reputation: 4287

The method looks fine as it uses the same arguments as Backbone describes:

model.save([attributes], [options])

The most likely scenario is that your success/error handlers are being overridden somewhere up the prototype chain and not calling your handlers.

Upvotes: 1

Related Questions