window.open和发送表单数据不起作用 [英] window.open and sending form data not working
本文介绍了window.open和发送表单数据不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试打开新窗口并发送表单数据 使用 javascript 和 jquery-1.8.3 .但是,这并不令人担忧.
I'm trying to open new window and send form data with javascript and jquery-1.8.3. But, It's not woriking.
这是源代码.
<a href="#" onclick="printPage()">Print this</a>
<script type="text/javascript" src="/common/js/jquery-1.8.3.min.js"></script>
<script type="text/javascript">
function printPage(){
var form = $("<form method='post' action='/common/print.jsp' target='printWindow'></form>");
var input = $("<input type='hidden' name='view'/>");
input.val($("#ctn").html());
form.append(input);
var printWindow = window.open(form.attr("action"), "printWindow", "width=700px,height=800px");
form.submit();
}
</script>
窗口已打开.但是request.getParameter("name")
为空.
window was opened. But request.getParameter("name")
is null.
这是/common/print.jsp
页
<%@ page contentType="text/html; charset=utf-8"%>
<% request.setCharacterEncoding("UTF-8"); %>
<div id="ctn">
<%
out.print(request.getParameter("view"));
%>
</div>
这段代码有什么问题?
What's the problem in this code?
推荐答案
您是否在伪造ajax调用;-)
Are you faking an ajax call ;-)
最好您做这样的事情:
<a href="#" onclick="printPage()">Print this</a>
<script type="text/javascript" src="/common/js/jquery-1.8.3.min.js"></script>
<script type="text/javascript">
function printPage(){
$.post('/common/print.jsp', {view:$("#ctn").html()}).success(function(response){
var oWindow = window.open('', "printWindow", "width=700px,height=800px");
oWindow.document.write(response);
});
}
</script>
这篇关于window.open和发送表单数据不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文