Asynchronous File Upload using AjaxFileUpload. js

Source: Internet
Author: User

Ajax cannot submit files. Therefore, when uploading and previewing images, we often use Ifame to achieve seemingly asynchronous results. However, this is not always very convenient, AjaxFilleUpload. js wraps the above method so that we do not need to manage a series of Iframe operations or affect our page structure to implement asynchronous file submission.

Html:

 


Js:

$. AjaxFileUpload ({url: '$ {pageContext. request. contextPath}/Manage/BR_restorePic.action ', // link to the server address secureuri: false, fileElementId: 'file _ upload', // id attribute dataType: 'text' in the file selection box ', // The format returned by the server can be json or xml success: function (data, status) // equivalent to the usage of the try statement block in java {condition ('character restoredialog'character .html (data ); // alert (data) ;}, error: function (data, status, e) {// equivalent to the usage of catch statement blocks in java ('{restoredialog'{.html ("Upload Failed, please try again ");}});


This method also has a problem, that is, the input can only be used once, and the second onchange of the input will not be executed, which should be related to the browser. The solution is to replace the input

Like this:

$('#file_upload').replaceWith('');


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.