我有以下的AJAX函數來更新點擊的投票。AJAX/Jquery更新只有特定的div點擊特定的按鈕
$(function() {
$(".vote").click(function()
{
var id = $(this).attr("id");
var name = $(this).attr("name");
var dataString = 'id='+ id ;
var parent = $(this);
if (name=='up')
{
$(this).fadeIn(200).html('<img src="/content/voting/yes-enb.JPG" />');
$.ajax({
type: "POST",
url: "up_vote.php",
data: dataString,
cache: false,
success: function(html)
{
parent.html(html);
}
});
}
});
和DIV/SPAN HTML代碼如下
<span class="vote" id="53" name="up" style="text-decoration:none; color:none; margin:5px; ">
<img src="/content/voting/yes-enb.png" width=12 height=12 alt="">
<span style="text-decoration:none; color:none">'.$up.' </span></span>
所以上面的AJAX代碼在用戶每次點擊投票按鈕時,計數器加1。然而在這種情況下,投票img以及投票數量都會刷新。我想要的是'。$ up'。部分被刷新。那只是投票部分。
任何想法如何做到這一點?