我尝试根据从IFrame发送到另一个处理器文件的$ .post请求的结果显示消息。
//begin script
function sendForm() {
$.post("http://www.website.com/main/post.php",$("#testForm").serialize(),function(data,status){
$("#result").html(data)
});
return false
}
$(document).ready(function() {
$("#testForm").submit(sendForm);
});
//end script
//form in an IFrame
//the IFrame is in a url like http://website.com/main/module/footer.php
<form id="testForm" method="post">
<label for="email">Enter your email</label>
<input id="email" name="email" type="text" required="yes" validate="email" message="Please enter a valid email address" class="replaceText" value="Enter your email"/>
<input id="subscribe" type="image" src="signup.png"/>
</form>
//this is where output from $.post request should be displayed
<div id="result"></div>
//end
我尝试过以下操作并且工作正常,显示来自$ .post的消息,
//scripts were disabled/commented out
//form in an IFrame
<form id="testForm" action="http://www.website.com/main/post.php" method="post">
<label for="email">Enter your email</label>
<input id="email" name="email" type="text" required="yes" validate="email" message="Please enter a valid email address" class="replaceText" value="Enter your email"/>
<input id="subscribe" type="image" src="signup.png"/>
</form>
<h5><div id="result"></div></h5>
但是,因为表单位于IFrame中,所以它会加载显示脚本消息的整个IFrame。我只需要在不破坏整个IFrame的情况下显示消息。
注意:我需要保留IFrame,不能更改文件post.php。
非常感谢提前。
答案 0 :(得分:0)
最简单的方法是在主页上为您的iframe添加name
,而不是
$("#result").html(data)
说
$('#result', frames['myFrameName'].document).html(data)