$.ajax({
url: “******”,
cache: false,
contentType:"multipart/form-data",
dataType: "json",
type: "POST",
contentType: false,
processData: false,
data: formData,
xhr:function(){
myXhr = $.ajaxSettings.xhr();
if(myXhr.upload){// check if upload property exists
myXhr.upload.addEventListener('progress',function (e) {
// event.total是需要传输的总字节,event.loaded是已经传输的字节。如果event.lengthComputable不为真,则event.total等于0
if (e.lengthComputable) {
var progress = Math.round(e.loaded / e.total * 100)+ "%";//已上传的进度
}
},false);// for handling the progress of the upload
}
return myXhr;
},
success: function (result) {
},
error: function (e) {
}
})
网友评论