有一个简单的网页发送请求,由 servlet 类处理和操作并发回响应 text
。而我想要 ajax
类型处理请求客户端,这就是为什么我将响应目标提供给一个不可见的 iframe。 *但是我想在iframe得到响应后在页面上打印success
*
<html> <body>
<form action="test" method="post" target="IFrame"> /*response target is iframe*/
<input type="text" name="logic" />
<input type="submit" value="Submit" />
</form>
<iframe name="IFrame" style="width:0; height:0"> </iframe>
</body> </html>
我认为这可以使用 javascript
或 jquery
来完成,如果您有任何想法,请指导我。
最佳答案
在 iframe 加载的页面中,您需要调用父函数。
<!-- This is the Parent. Call it JSTest1.html -->
<html>
<head>
</head>
<body>
<script type="text/javascript">
function parentAlert() {
alert('hey there from the parent');
}
</script>
I'm the parent
<iframe src="/JSTest2.html"></iframe>
</body>
<!-- this is the iframe html loaded. Call it JSTest2.html-->
<html>
<head>
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
</head>
<body>
<script type="text/javascript">
$(document).ready( function() {
window.parent.parentAlert();
});
</script>
In the Iframe.
</body>
关于java - 如何从 <form target ="IFrame"> 得到响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7631435/