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.