表单不会在自动刷新页面上提交
问题描述:
我在PHP中有Web应用程序,我需要在此页面中的一些变量来自动刷新。因此,我已将该处理放在另一个页面 - “test.php”中 - 每隔10秒将其加载到该div中。表单不会在自动刷新页面上提交
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.0/jquery.min.js"></script>
<script type="text/javascript">
var auto_refresh = setInterval(function()
{
$('#refresh').load('test.php').fadeIn("slow");
}, 10000);
</script>
</head>
<body>
<div id="refresh">
</div>
</body></html>
的问题是,这个网页具有上点击,不会不提交值并做处理,因为它是应该做的一种形式。没有自动刷新代码,它工作正常。我如何克服这个问题?
的test.php的包含这种形式:
<form action="count.php" method="post">
<?php
$votes = getVoteCount($popular[$i][1]);
$voted=checkVoted($screenName,$id);?>
<td><img src="<?php echo $popular[$i][4]; ?>" width=60></td>
<td align="center"><CITE><?php echo "@".$username; ?></CITE>
<?php echo "<br >".$text.
"<br >".$votes." votes |";?>
<?php
if($screenName!=$username && $voted==false){
?>
<input type="hidden" name="addID" value="<?php echo $id;?>">
<input type="hidden" name="username" value="<?php echo $screenName;?>">
<INPUT TYPE="image" src="images/vote.png" name='vote' ALT="Submit Form" onMouseOver="this.src='images/vote_link.png'"
onMouseOut="this.src='images/vote.png'" width="35" height="20" title="Click to Vote!"></form>
<?php }else if($voted){ ?>
<img src="images/voted.png" width="35" height="20" title="You have already voted">
<?php } else{
echo "<img src='images/authored.png' width='40' height='20'>";
}?>
答
因为你重装与Ajax请求的页面,您不再可以使用
$("submit-button").click()
或
$("submit-button").submit();
你将需要使用jQuery的live,delegate或on来做到这一点。 (Live是不再这样做的推荐方式。
$("body").on("click", "submit-button", function()
{
//execute code here
});
或
$("body").on("submit", "submit-form", function()
{
//execute code here
});
怎么没装形式看起来像你在使用提交? – 2012-02-09 22:41:50
?JavaScript中,形式....? – PFY 2012-02-09 22:42:18
@Muhammad:我在test.php页面的表格标签中添加了 – codingNewbie 2012-02-09 22:58:21