JQuery does not use plug-ins and swf to upload non-refreshing files. jqueryswf

Source: Internet
Author: User

JQuery does not use plug-ins and swf to upload non-refreshing files. jqueryswf

File Upload is a common function for websites, such as the attachment or image upload function. There are also many solutions. Today we will introduce a new file upload method with no refreshing jQuery.

First, we put a form in the page to upload files:

Copy codeThe Code is as follows:
<Form id = "myForm" method = "post" action = "/asyncFileUpload/UploadHandler. ashx"
Enctype = "multipart/form-data" target = "asyncTarget">
<Span> file: </span>
<Input type = "file" name = "myFile"/>
</Form>
<Input type = "button" value = "Upload" id = "btnUpload"/>

Then, put an iframe in the page and refresh the iframe when uploading, instead of the entire webpage:

Copy codeThe Code is as follows:
<Iframe name = "asyncTarget" style = "display: none;"> </iframe>

Next, use js to add the button function:

Copy codeThe Code is as follows:
<Script>
$ (Function (){
$ ("# BtnUpload"). click (function (){
$ ("# MyForm"). submit ();
});
});
</Script>

Click the button to submit the form.

This scheme can be used to easily implement non-refreshing file uploads. The implementation idea is: submit the form to an iframe, And the other processing is like processing a common form commit.

To be improved, we have only one idea: Listening to the readystate of iframe through js and parsing the content of iframe.

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.