Have an IFrame (display: none) in your form and set an iframe for your purpose.
My form is as follows:
<iframe id="upload_target" name="upload_target" src="" style="width:0px;height:0px;border:0px solid #fff;"></iframe> <form enctype="multipart/form-data" name="frmXMLUpload" target="upload_target" action="scripts/uploadXML.php" method="POST" onSubmit="return checkExtension(fXMLFile.value, 'xml')"> <input type="hidden" name="MAX_FILE_SIZE" value="30000" /> <input name="fXMLFile" id="fXMLFile" type="file" accept="text/xml" size="50" /> <p><input type="submit" value="Upload" /></p> </form>
And answer the answer in IFRAME. basically it is not AJAX at all, but who would like JavaScript to have access to files on your local computer? It is beautiful as it is.
source share