<! DOCTYPE html>If you want to implement Ajax in jquery, the Ajax method of jquery does not operate on the Progress event, at which point the XMLHttpRequest object that needs to be called is the specified progress event.
$.ajax ({ type: "POST", url: "Upload", data:formdata,///The data uploaded here uses the FormData object Processdata:false,//Must be false to self- Add the correct content-type contenttype:false,//Here we get the XMLHttpRequest object created by jquery, add progress event bindings for it, and then return to Ajax for use XHR : function () {var xhr = $.ajaxsettings.xhr (); if (onprogress && xhr.upload) {xhr.upload.onprogress = progressfunction;
return XHR;
}
}
});
XMLHttpRequest object, when transmitting data, there is a progress event, which is used to return the progress information.
It is divided into two cases of uploading and downloading
1) The downloaded Progress event belongs to the XMLHttpRequest object
2) The uploaded progress event belongs to the Xmlhttprequest.upload object.
Download Progress implementation:
xhr.onprogress = Downloadprogress;function DownloadProgress (event) {//Not tested if (event.lengthcomputable) { var PercentComplete = Event.loaded/event.total; }}
JS File Upload progress bar