Meteor最近的更新为http包添加了一个使用beforeSend的选项,允许我们访问客户端上的xhr对象。我偶尔在客户端上传或下载大文件,我想要一个进度指示器和一个取消选项。不幸的是,在发送之前我无法获得。
问题
使用beforeSend的正确方法是什么和/或为什么我的代码不起作用?
发生了什么
Http.call完全运行,但我的beforeSend函数永远不会执行。
相关套餐
相关客户代码
httpProgress = function(xhr) {
console.log('I never see this');
xhr.onprogress = function(e) {
if (e.lengthComputable) {
setProgress((e.loaded / e.total) * 100, 'downloading...', true);
}
else{
setProgress(-1, 'downloading...', true);
}
};
};
HTTP.call('GET',url, {
beforeSend: httpProgress,
headers: {
'Accept': '*/*'
},
responseType: 'arraybuffer' //using aldeed:http here
}, function(error, result) {
...
}
);
关于beforeSend的流星文档
在客户端上,将在发送请求之前调用此方法 为了更直接地操作底层的XMLHttpRequest对象, 它将作为第一个参数传递。如果回调返回 如果是,请求将不会被发送。