表单未在自动刷新的页面上提交

时间:2012-02-09 22:31:07

标签: php javascript jquery form-submit page-refresh

我在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'>";
    }?>

1 个答案:

答案 0 :(得分:0)

因为您正在使用ajax请求重新加载页面,所以您无法再使用

$("submit-button").click() 

$("submit-button").submit();

您需要使用jquery的live,delegate或on来执行此操作。 (实时不再是推荐的方式。

$("body").on("click", "submit-button", function()
 {
     //execute code here
 });

$("body").on("submit", "submit-form", function()
 {
     //execute code here
 });