Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Uploading file in a form without page refresh

I have this bit of code:

<form name="myUploadForm" method="post" action="/scripts/upload.do" enctype="multipart/form-data" id="fileUpload">
   <table width="100%" border="0"> 
      <tr>
         <td>
            <input type="file" name="xlsFile" size="60" value="test.xls"> 
            <input type="button" value="Upload File" name="upload_xls">
         </td>
      </tr>
   </table>
</form>

Right now I can upload the file with Struts but it refreshes the page. How do I do this without the page refreshing?

like image 826
Mark Avatar asked Dec 21 '22 15:12

Mark


1 Answers

What worked for me:

On the form tag, I have target="hidden-iframe"

the hidden i-frame on the page looks like this:

<iframe name="hidden-iframe" style="display: none;"></iframe>

The important thing to underline here is that the form is referencing the name attribute of the frame and not the id.

like image 98
justian17 Avatar answered Dec 24 '22 06:12

justian17