window.onload = function(){
var xhr = new XMLHttpRequest();
xhr.open('GET', "http://localhost:8080/myblog/helloworld.pdf");
xhr.responseType = 'arraybuffer';
xhr.onreadystatechange = function getPdfOnreadystatechange(e) {
console.log("xhr.readyState:"+xhr.readyState+" xhr.status:"+xhr.status);
if (xhr.readyState === 4) {
if (xhr.status === 200) {
var data = (xhr.mozResponseArrayBuffer || xhr.mozResponse ||
xhr.responseArrayBuffer || xhr.response);
console.log(data);
} else {
console.log("error");
}
}
};
xhr.send(null);
}
Ajax访问文件获取字节流方法
最新推荐文章于 2024-05-21 10:59:11 发布