2012-02-09 79 views
1

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

怎麼沒裝形式看起來像你在使用提交? – 2012-02-09 22:41:50

+0

?JavaScript中,形式....? – PFY 2012-02-09 22:42:18

+0

@Muhammad:我在test.php頁面的表格標籤中添加了 – codingNewbie 2012-02-09 22:58:21

回答

0

因爲你重裝與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 
});