javascript - Overriding the Jquery ajax success -
hi have base model -
var basemodel = backbone.model.extend({ initialize : function(input){ // base initialization implementation common concrete models }, ajaxcall : function(input){ var dfd = new jquery.deferred(); $.ajax({ type: 'get', url: input.url, success:function(data){ // on success implementation dfd.resolve(data); }, error:function(){ dfd.reject(); } }); return dfd.promise(); } });
now, want create concretemodel extends basemodel's fetch function , overrides ajax success
var concretemodel = basemodel.extend({ ajaxcall : function(input){ basemodel.prototype.ajaxcall.call(this, input); // how override ajax success implementation }
});
how override ajax success implementation in ajaxcall function of concretemodel.
thanks.
you can define ajax call successful callback 1 of base model method:
var basemodel = backbone.model.extend({ initialize : function(input){ // base initialization implementation common concrete models }, ajaxcall : function(input){ var dfd = new jquery.deferred(); $.ajax({ type: 'get', url: input.url, success:this.onsuccess, error:function(){ dfd.reject(); } }); return dfd.promise(); }, onsuccess: function(data){ // on success implementation dfd.resolve(data); } });
then override implementation in onsuccess function of concretemodel
var concretemodel = basemodel.extend({ onsuccess: function(data){ alert("hello concrete mode: "+data); } });
Comments
Post a Comment