我有一个提供 ajax 帖子的 ember 服务
import Ember from 'ember';
import ENV from '../config/environment';
export default Ember.Service.extend({
save(data) {
return new Ember.RSVP.Promise(
function (resolve, reject) {
function progress(e){
if(e.lengthComputable){
let max = e.total;
let current = e.loaded;
let Percentage = (current * 100)/max;
console.log(Percentage);
if(Percentage >= 100)
{
// process completed
}
}
}
Ember.$.ajax({
type: 'POST',
enctype: 'multipart/form-data',
url: ENV.APP.API_HOST + '/profile/lampiran-desas',
processData: false,
contentType: false,
cache: false,
data: data,
xhr: function() {
let myXhr = $.ajaxSettings.xhr();
if(myXhr.upload){
myXhr.upload.addEventListener('progress',progress, false);
}
return myXhr;
},
success: function (response) {
resolve(response);
},
error: function (error) {
reject(error);
}
});
});
}
});
成功响应在我的组件中正常返回。但是如何让我的函数进度返回。所以我可以在我的模板上制作一个加载进度条..?
谢谢..