XHR2:让使用纯JS实现上传进度条变成了可能
$.ajax({
xhr: function () {
var xhr = new window.XMLHttpRequest();
xhr.upload.addEventListener("progress", function (evt) {
if (evt.lengthComputable) {
var percentComplete = parseInt(evt.loaded / evt.total * 100) + "%";
config.progress.find('.prog').css({ 'height': percentComplete, 'background': "rgba(209,3,17,.5)" });
config.progress.find('.number').html(percentComplete);
}
}, false);
return xhr;
},
type: 'POST',
url: lanh.apiHost + "service/user/upload.html",
data: {
type: config.type,
filename: config.filename,
pic: config.pic
},
success: function (data) {
}
相关辅助网址:http://blog.sina.com.cn/s/blog_54da57aa01016n9i.html