var xhr = cc.loader.getXMLHttpRequest();
xhr.responseType = 'arraybuffer';
xhr.onreadystatechange = function () {
cc.info("xhr.readyState " + xhr.readyState);
cc.info("xhr.status " + xhr.status);
if (xhr.readyState === 4) {
if (xhr.status === 200) {
saveFile(xhr.response);
} else {
//下载失败 返回 弹出提示框
}
}
}
//.bind(this);
// xhr.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
xhr.setRequestHeader("Content-Type","application/octet-stream");
xhr.open("GET", url, true);
xhr.onprogress = function (event) {
if (event.lengthComputable) {
cc.info("xhr.onprogress event.loaded " + event.loaded);
cc.info("xhr.onprogress event.total " + event.total);
}
}
xhr.send();
xhr.onprogress 在native 上没有回调
xhr.status 打印的状态也只有 4