|
|
@ -123,41 +123,46 @@ try { |
|
|
|
//正在上传
|
|
|
|
//正在上传
|
|
|
|
isUploading = true; |
|
|
|
isUploading = true; |
|
|
|
//设置上传的数据
|
|
|
|
//设置上传的数据
|
|
|
|
var fd = new FormData(); |
|
|
|
var reader = new FileReader(); |
|
|
|
fd.append("Filename", file.name); |
|
|
|
reader.readAsDataURL(file); |
|
|
|
fd.append("Filedata", file); |
|
|
|
reader.onload = function (e) { |
|
|
|
//设置当前的上传对象
|
|
|
|
var data = e.target.result; |
|
|
|
currUploadfile = file; |
|
|
|
var fd = new FormData(); |
|
|
|
|
|
|
|
fd.append("fileName", file.name); |
|
|
|
if (XHR.readyState > 0) { |
|
|
|
fd.append("fileData", data); |
|
|
|
XHR = new XMLHttpRequest(); |
|
|
|
//设置当前的上传对象
|
|
|
|
|
|
|
|
currUploadfile = file; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (XHR.readyState > 0) { |
|
|
|
|
|
|
|
XHR = new XMLHttpRequest(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
XHR.upload.addEventListener("progress", progress, false); |
|
|
|
|
|
|
|
XHR.upload.addEventListener("load", requestLoad, false); |
|
|
|
|
|
|
|
XHR.upload.addEventListener("error", error, false); |
|
|
|
|
|
|
|
XHR.upload.addEventListener("abort", abort, false); |
|
|
|
|
|
|
|
XHR.upload.addEventListener("loadend", loadend, false); |
|
|
|
|
|
|
|
XHR.upload.addEventListener("loadstart", loadstart, false); |
|
|
|
|
|
|
|
XHR.open("POST", config.url); |
|
|
|
|
|
|
|
XHR.send(fd); |
|
|
|
|
|
|
|
XHR.onreadystatechange = function () { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//只要上传完成不管成功失败
|
|
|
|
|
|
|
|
if (XHR.readyState == 4) { |
|
|
|
|
|
|
|
console.log("onreadystatechange ", XHR.status, +new Date()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (XHR.status == 200) { |
|
|
|
|
|
|
|
uploadSuccess(currUploadfile, {}, XHR.status) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
uploadError() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//进行下一个上传
|
|
|
|
|
|
|
|
nextUpload() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
XHR.upload.addEventListener("progress", progress, false); |
|
|
|
|
|
|
|
XHR.upload.addEventListener("load", requestLoad, false); |
|
|
|
|
|
|
|
XHR.upload.addEventListener("error", error, false); |
|
|
|
|
|
|
|
XHR.upload.addEventListener("abort", abort, false); |
|
|
|
|
|
|
|
XHR.upload.addEventListener("loadend", loadend, false); |
|
|
|
|
|
|
|
XHR.upload.addEventListener("loadstart", loadstart, false); |
|
|
|
|
|
|
|
XHR.open("POST", config.url); |
|
|
|
|
|
|
|
XHR.send(fd); |
|
|
|
|
|
|
|
XHR.onreadystatechange = function () { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//只要上传完成不管成功失败
|
|
|
|
|
|
|
|
if (XHR.readyState == 4) { |
|
|
|
|
|
|
|
console.log("onreadystatechange ", XHR.status, +new Date()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (XHR.status == 200) { |
|
|
|
|
|
|
|
uploadSuccess(currUploadfile, {}, XHR.status) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
uploadError() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//进行下一个上传
|
|
|
|
|
|
|
|
nextUpload() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//请求完成,无论失败或成功
|
|
|
|
//请求完成,无论失败或成功
|
|
|
|