如何prevent页面重定向/表格后提交刷新,而preserving文件输入? jQuery的 [英] How to prevent page redirection/refresh after form submit, while preserving file input? Jquery
本文介绍了如何prevent页面重定向/表格后提交刷新,而preserving文件输入? jQuery的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个文件上传表单如下:
I have a file upload form as follows:
<form id="upload" action="someurl" method="post" enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="file" />
<input type="submit" value="submit" />
<form>
问题是,我每次提交表单时,我会被重定向到表单的操作URL。
Problem is that every time I submit the form I will be redirected to the form's action url.
我如何提交此表,同时仍停留在同一页上?使用AJAX或preventDefault将无法正常工作,我就失去了文件流。
How do I submit this form while still staying on the same page? Using ajax or preventDefault won't work as I will lose the file stream.
Rendy
推荐答案
只要你有一个 IFRAME
您的页面是隐藏的,在
Provided you have an iframe
on your page that's hidden,
<iframe id="hidden-iframe"></iframe>
然后添加一个目标
到您的窗体:
<form id="upload" action="someurl" method="post" target="hidden-iframe" enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="file" />
<input type="submit" value="submit" />
<form>
大功告成!
这篇关于如何prevent页面重定向/表格后提交刷新,而preserving文件输入? jQuery的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文