我在一个javascript脚本中有一个AJAX请求,在那里我得到了一个这样的文件:
$.ajax({
type: "GET",
url: "./" + img_type + ".bmp",
dataType: "html",
timeout: test_timeout,
cache: false,
success: function(msg)
{
//some stuff
}
});代码本身是正确的,并且可以完美地工作。有没有办法在请求还在进行的时候知道我下载了多少文件??我的意思是,一旦请求给我一个成功的消息,我知道我已经下载了整个文件,但如果我想知道两秒钟后开始呢?谢谢!
发布于 2012-12-30 00:29:11
下面是一个例子:
var xhr = new XMLHttpRequest;
xhr.onprogress = function(e){
if(e.lengthComputable){
var progress = e.position || e.loaded;
var total = e.totalSize || e.total;
var percent = progress/total*100;
//do something with progress here
}
};
xhr.onload = function(){
var content = xhr.responseText;
//do something with the result here
};
xhr.open('GET','./'+type+'.bmp',true);
xhr.send();发布于 2012-12-30 00:21:03
https://stackoverflow.com/questions/14083322
复制相似问题