It is not necessary to make different values, you can just give all the buttons the same class and then use js to catch a click
$("body").on("click",".badges",function()
To transfer attributes you can simply add <button id_favorite="тут само ID"></button
and transfer it to ajax and do what you want
data:{"id_favorite":$(this).attr("id_favorite"),}
I did this:
HTML + PHP - I hung up on the id_badges button and pasted the ID of what you need to cram into your favorites
<a id_badges="<? echo $product_arr['id']; ?>" type_badges="add_favorites" class="favorites icons badges" <? if($product_arr['star'] == '1'){echo'id="star"';}; ?> ><span class="glyphicon glyphicon-star"></span></a>
AJAX itself, everything is simple, I pass the attributes id_badges and type_badges through POST
$("body").on("click",".badges",function(){ $.ajax({ type:'POST', url:"/php/deleted.php", data:{"id_badges":$(this).attr("id_badges"),"type_badges":$(this).attr("type_badges")}, success:function(data){ $(".refresh").html(data); } }); });
PHP handler - I process it and add it to the database, in the end I need to update the block update as well
if($type_badges == "add_favorites"){ $data = mysql_fetch_assoc(mysql_query("SELECT `user`,`star` FROM `product` WHERE `user`='".$user."' && `id`='".$id_badges."' LIMIT 1")); if($data['star'] == '0'){ $star = "1"; print '<div class="alert succes alert-dismissable"><button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button><span class="glyphicon glyphicon-star"></span> Добавлено в избранное</div>'; } else if($data['star'] == '1'){ $star = "0"; print '<div class="alert succes alert-dismissable"><button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button><span class="glyphicon glyphicon-trash"></span> Удалено из избранного</div>'; } mysql_query("UPDATE `product` SET `star`='".$star."' WHERE `id`='".$id_badges."'"); };