Based on HTML5 Ajax implementation file upload and display progress bar _ajax related

Source: Internet
Author: User
Tags readfile

This article illustrates the Ajax upload file and progress bar implementation methods, share for everyone to reference, the specific content as follows

Effect Chart:

HTML5 upload is the way of synchronous upload, so can achieve the display of progress bar.
1. Upload file:

First we use Ajax to get the file object of <input type= "file" id= "File_upload" >:

var file = null; 
var input = $ ("#file_upload"); 
File domain when selecting files, execute readFile function 
input.addeventlistener (' Change ', readfile,false); 
function ReadFile () { 
 file = This.files[0]; 

Then use Formdata () to send to the background.

 var fd = new FormData (); 

2. Monitor event: to add the XMLHttpRequest in the upload, you can get the uploaded file size, to achieve the display of progress bar.

 
Monitor event 
Hr.upload.addEventListener ("Progress", uploadprogress, false); 

The complete code is as follows:

 

The above is about Ajax to achieve with the progress of the file upload all the content, I hope to help you learn.

Related Article

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.