JS File Upload progress bar

Source: Internet
Author: User
Tags file upload progress bar

<! 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

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.