Very interesting situation!
The code below represents order entry. Before saving User should calc order Total what he does by clicking on #calcTotal button and then he clicks on #saveOrder button.
The problem is that if User launches saveOrder function just for one time then ajax method in calcTotal function will always call for model.save in saveOrder function!
I think this.model.save function override some Backbone model functions so any ajax request will execute any actions in model.save.
How I should prevent this behaviour?
events: {
'click #calcTotal': 'calcTotal',
'click #saveOrder': 'saveOrder'
},
calcTotal: function() {
this.model.set( $('form').serializeJSON() );
var that = this;
$.ajax({
url: 'api/order/calcTotal',
type: 'GET',
data: this.model.toJSON(),
dataType: 'json',
success: function( result ) {
that.model.set({
'total': result.total
});
that.renderTotal();
}
});
},
saveOrder: function() {
var that = this;
this.model.save({
success: function() {
console.log('CHECK');
}
});
},