File Upload display progress (JS code implementation, not suitable for multiple relay display)

Source: Internet
Author: User

$.Ajax ({
Url:basepath +"/container" +"/upload" +"? _t=" +New Date ().GetTime (),
DataType:' JSON ',
Data:form,
Type:' POST ',
ProcessData:False,//TellJqueryDo not process the sent data
ContentType:False,
Xhr:function () {
MYXHR =$.Ajaxsettings.XHR ();
IfMyxhr.Upload) {
Myxhr.Upload.AddEventListener (' Progress ',Function (e) {
if (e.lengthcomputable) {
var percent = Math.Floor (E.loaded/e.total*100);
If (Percent <=100) {
$ ("#J_progress_bar"). Progress (' Set progress ', percent);
$ ("#J_progress_label"). HTML ('Uploaded:' +percent+ '% ');
Console.Log (percent)
}
If (Percent >=100) {
$ ("#J_progress_label"). HTML ('File upload complete, please wait...‘);
$ ("#J_progress_label"). AddClass (' success ');
Console.Log (percent)
}
}
},False;
}
ReturnMyxhr;
},
Success: function (res) {
// request succeeded
},
Error: function (res) {
// request failed
Console. log (res);
}

})


Display the progress of the upload, the data parameter for the specific use of formdata formdata can self-query data

Welcome Dabigatran Exchange: 589780530

File Upload display progress (JS code implementation, not suitable for multiple relay display)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.