JS No refresh Upload file

Source: Internet
Author: User

The traditional way of uploading files

<formAction=""Method= "POST"enctype= "Multipart/form-data"><inputtype= "File"name= "File"/><inputtype= "Submit"/></form>

After the upload is performed, the page jumps to the address specified by the action.

The general user needs to upload a file with no page refresh, at which point the IFRAME can be used to redirect the returned content after the form form is submitted to the IFRAME.

The modified code is

<formAction=""Method= "POST"Target= "Target"enctype= "Multipart/form-data"><inputtype= "File"name= "File"/><inputtype= "Submit"/></form><iframename= "Target"ID= "Target"frameborder= "0"width= "0"Height= "0"></iframe><Script>    variframe=document.getElementById ("Target"); varUploadcallback= function() {console.log (Iframe.contentDocument.body.innerHTML);    }; Iframe.onload=Uploadcallback;</Script>

The onload event of the IFRAME is used to detect whether the transmission is complete and to obtain the return value of the service side after the transfer.

The example is very simple and there is a case of browser incompatibility, but the basic idea of uploading plugins is so.

In addition, there are SWF ways to achieve the actual upload speed and progress and other information.

JS No refresh Upload file

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.