2013-07-03 21 views
0

如果rating = +0,則會顯示以下內容(待機)。AJAX POST不按類按鈕單擊加載類。

enter image description here

如果我按一下按鈕,然後下面就會顯示(加入等級)。

enter image description here

如果我再次點擊,然後下面就會顯示(除去等級)

enter image description here


我想讓它顯示如下:

如果rating = +0,當我點擊它時,將顯示以下內容。

enter image description here

問題:當我點擊按鈕的字體重量:大膽&顏色:#消失時,它應該會自動與類更新。我究竟做錯了什麼?對不起,這個蹩腳的問題,只是在它一段時間,我堅持這樣一個簡單的問題,我敢肯定。

這是我的代碼:

PHP:

<div class="up vote" name="voteUp" id="<?php echo $post_iD;?>"> 
    <div class="wrapper">+<?php echo $VoteRate;?></div> 
</div> 

AJAX:

$(function() 
{ 
    $(".vote").click(function() 
    { 
     var id = $(this).attr("id"); 
     var name = $(this).attr("name"); 
     var dataString = 'id='+ id ; 
     var parent = $(this); 

     if (name=='voteUp') 
     { 
      $.ajax(
      { 
       type: "POST", 
       url: "voting/up_vote.php", 
       data: dataString, 
       cache: false, 
       success: function(html) 
       { 
        parent.html(html); 
       } 
      }); 
     } 
     return false; 
    }); 
}); 
+0

只是一個說明。如果你使用的是高於1.7.2的jquery,那麼'success'已經被棄用了。改用'.done()'。 – itachi

+0

那我現在沒有,我正在使用最新的.. 1.10.1 – iBrazilian

回答

1

在你的成功的功能,更換.wrapper div的HTML,而不是父:

parent.find(".wrapper").html(html); 
+0

不是$(「。wrapper」,this)?? – Guerra

+0

'this'指的是AJAX成功功能。 – tymeJV

+0

真的嗎?我認爲它正在向$('。vote')節點傾斜,因爲它是點擊功能。但不確定。如果這個上下文中的「this」將會傾向於ajax成功函數,那麼你是對的。 – Guerra