2
我試圖實現一個解決方法來解決與多部分表單數據一起使用AJAX的問題。 This page看起來不錯。基本上,不是使用AJAX,而是將表單提交的輸出重定向到iframe。但是,它並不適合我。這是我的客戶端HTML代碼:如何將HTML表單提交重定向到iframe?
<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>
服務器端的處理看起來工作正常,但在客戶端的響應(IE7)是彈出一個文件下載「你想保存此文件,或者找到一個程序...「對話框。這裏是相關的服務器端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();
任何關於如何解決這個問題的建議?提前謝謝了。
簡單,甜美的解決方案。非常感謝! – 2011-04-28 13:29:52