PHP和类似AJAX的系统类似twitter系统

  • 本文关键字:系统 twitter AJAX PHP php ajax
  • 更新时间 :
  • 英文 :


我用PHP和AJAX制作了一个类似于twitter的系统。在某种程度上,我无法理解,当我只按一个按钮时,它适用于页面上的所有按钮。请帮忙。

在此处输入图像描述

index.php

<div id="rezbtn">
<span id="rezarea">
<button style="font-size:15px; float:left; <? if($sorus["soru_id"] == $rezs['soru_id'] && $user_id == $rezs['user_id']){ echo 'color:green;';}else{ echo ''; } ?>" class="btn rezle" id="rezle" type="button" title="<? echo $sorus["soru_id"]; ?>">
<span>#Rezle <? echo $rez["rez_id"]; ?></span>
</button>
</span>
</div>

ajax.php

if($rezuscount > 0)
{
echo "<span style='color:black;'>#Rezle ", $rezcount-1,"</span>";
}
else
{
echo "<span style='color:green;'>#Rezle ", $rezcount+1,"</span>";
}

类似.js

$('.rezle').click(function(){
var soruid = $(this).attr("title");
$.ajax({
type:"POST",
url:"ajax.php",
data:{"soru":soruid},
success:function(e)
{
$('.rezle').html(e);
}
})
});

我的代码是这样的。

这里的问题是,您使用类rezle引用所有元素,并使用ajax html响应更新所有元素:

$('.rezle').html(e);

试试这个:

$('.rezle').click(function(){
const rezle_button = this;
var soruid = $(this).attr("title");

$.ajax({
type:"POST",
url:"rezle.php",
data:{"soru":soruid},
success:function(e)
{
$(rezle_button).html(e);
}
})
});

最新更新