简体   繁体   English

如何将 HTML 表单提交重定向到 iframe?

[英]How can I redirect HTML form submission to an iframe?

I'm trying to implement a workaround to the problem of using AJAX with multi-part form data.我正在尝试解决将 AJAX 与多部分表单数据一起使用的问题。 This page looks like a good idea.这个页面看起来是个好主意。 Bascially, instead of using AJAX you redirect the output of the form submission to an iframe.基本上,不是使用 AJAX,而是将表单提交的 output 重定向到 iframe。 However, it isn't quite working for me.但是,它对我来说不太有效。 Here's my client-side HTML code:这是我的客户端 HTML 代码:

<form id="submitDocumentForm" target='upload_target' name="submitDocumentForm" enctype="multipart/form-data" action="MyServlet" method="POST">
   <input id="inputFile" type="file" name="inputFile"/>
   <input type="submit" value="Import Document" />
   <iframe id="upload_target" name="upload_target" src="" style="width:100;height:100;border:0px solid #fff;"></iframe>
</form>

The server side processing seems to work fine, but the client side response (IE7) is to pop up a File Download "Do you want to save this file, or find a program..." dialog box.服务器端处理似乎工作正常,但客户端响应(IE7)是弹出一个文件下载“你想保存这个文件,还是找到一个程序......”对话框。 Here's the relevant server side Java code:下面是相关的服务器端Java代码:

//handling of the file and exception handling omitted
JSONObject responseData = new JSONObject();
responseData.put("messages", "Upload complete");
PrintWriter pw = response.getWriter();
response.setHeader(RESP_HEADER_CACHE_CONTROL, RESP_HEADER_VAL_NO_CACHE);
response.setContentType("application/json");
pw.println(responseData.toString());
pw.close();

Any suggestions as to how I might fix this?关于我如何解决这个问题的任何建议? Many thanks in advance.提前谢谢了。

Set the response's Content-Type to text/plain to force the browser to treat it as a document instead of a file.将响应的 Content-Type 设置为text/plain以强制浏览器将其视为文档而不是文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM