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('');