javascript - Angularjs HTTP service POST progress event -
since topics subject on year old, asked myself if there any solutions track ajax progress event http service (for loading bar or track how many bytes has downloaded). without use of 3rd parties :)
these events:
var ajax = new xmlhttprequest(); ajax.addeventlistener("progress") ajax.addeventlistener("load") ajax.addeventlistener("error") ajax.addeventlistener("abort")
i've made using promise notify progress :
var deferred = $q.defer(); var fd = new formdata(); fd.append("filename", file.name); fd.append("file", file); var xhr = new xmlhttprequest(); xhr.upload.addeventlistener("progress", function (event) { deferred.notify(event); }, false); xhr.addeventlistener("load", function (data) { deferred.resolve(event.target.response); }, false); xhr.addeventlistener("error", function (data) { deferred.reject(event.target.response); }, false); xhr.addeventlistener("abort", function (data) { deferred.reject(event.target.response); }, false); xhr.open("post", url); xhr.send(fd); return deferred.promise;
Comments
Post a Comment