我写了一个JavaScript,它使用Jquery.post从Web应用程序加载网页。我在iframe中显示页面。该网页显示在IE中,但不是在Firefox中。我试过使用Firebug,但没有错误,它有一个302 OK笔记。我试图更改也没有工作的Jquery源代码。试过JSON,也没有工作。它超过3天我正在尝试解决这个问题。我尝试了很多方法,但效果并不好。Jquery.post不工作在Firefox中
<html>
<head>
<script type="text/javascript"src="http://ajax.microsoft.com/ajax/jquery/jquery1.4.2.min.js">
</script>
<script type="text/javascript">
function callajax()
{
var iframe =document.createElement("iframe");
iframe.style.width="100%";
iframe.style.height="100%";
//app.getContentEl().appendChild(iframe);
document.body.appendChild(iframe);
jQuery.post('http://localhost:9090/simpleapp/formproc1', {'param':'rajat'},function(html){
var doc =iframe.contentWindow.document;
doc.write(html);
doc.close();
});
}
</script>
</head>
<body>
<p>Start typing a name in the input field below:</p>
<span></span>
<div id="display"></div>
First name:
<input type="text" />
<button onclick="callajax()">Click me</button>
</body>
</html>
我也会附上post方法,因为它也可能是一个错误的方法。
doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO自动生成方法存根
PrintWriter out = response.getWriter();
String par = request.getParameter("param");
System.out.print("Hiii this is inside POST method");
//out.println("<data><param>"+par+"</param></data>");
//out.println(par);
//out.flush();
//System.out.print(par);
response.sendRedirect("first.jsp");
// out.println("{\"redirect\":\"first.jsp\"}");
}
尝试把警报和检查方法按钮点击后调用。 – 2012-01-06 06:11:23
描述它如何“不起作用”。它是否创建iframe? iframe是否完全填充?你有没有尝试在firebug中手动调用jQuery.post函数? – codersarepeople 2012-01-06 06:12:38
非常感谢您的迅速响应。 Firebug没有显示任何错误。但是响应为空。请求成功通过。并且创建了iframe,但网页未填充到iframe中。现在你能帮我吗 – user1132583 2012-01-06 06:37:52