2010-08-28 25 views
5

林試圖voteup/votedown添加到我的網站之一,但林有幾個問題:jQuery的 - 發佈和回覆

首先,這裏是我的jQuery:

j(".voteup").click(function(){ // when people click an up button 
    j("div#response").show().html('<h2>voting, please wait...</h2>'); // show wait message 
    itemID = j(this).parent('div').attr('id');; // get post id 
    alert(itemID); 

    j.post(voteup.php,{id:itemID},function(response){ // post to up script 
     j("div#response").html(response).hide(3000); // show response 
    }); 

    j(this).attr({"disabled":"disabled"}); // disable button 
}); 

我voteup.php文件是:

<?php 

$id=$_POST['itemID']; 

echo '<h2>PHP Response: You voted post '.$id.' up</h2>'; 

?> 

但是它不似乎工作,警報來通過與後ID但從此之後就沒事。 $ id不會被echo'd。

任何想法?

+0

對不起,我可能會得到這個錯誤,但投票後上/下用戶仍然在網頁上,不會被重定向到voteup.php頁面,對不對?所以我認爲他/他無法看到該頁面的信息。 – 2010-08-28 09:36:50

回答

3

必須在voteup.php寫道

$id=$_POST['id'];

,而不是

$id=$_POST['itemID'];