jquery - overriding backbone js sync method to add xhr event listener -
sync: function(method,model,options){ options.beforesend = function(xhr,settings) { settings.xhr = function() { console.log('test'); } } return backbone.sync(method,model,options); }
i implement progress bar model fetch, , have added code above override sync access xhr method. however, doesn't seem fire or anything. i'm using jquery 2.0.3 , backbone 1.1.2
edit:
the problem have updateprogress fire once @ end.
options.beforesend = function(xhr,settings) { settings.xhr = function() { var xhr = $.ajaxsettings.xhr(); xhr.addeventlistener("progress", updateprogress, false); function updateprogress(event){ console.log('loaded:'+event.loaded+' total:'+event.total); math.ceil(event.loaded/event.total*100); } return xhr; }; }
Comments
Post a Comment