1
Good evening, is there any refresh function on anchor link without Reload on page? I am creating a system to like articles, but I would like to create a way to change the link "like" to "Unlike. I tried to make a location.href
but the page updates what I don’t want.
<script type="text/javascript">
function add_like(id_artigo){
$.post('php/add_like.php', {artigo_id:id_artigo}, function(dados){
if(dados == 'sucesso'){
get_like(id_artigo);
}else{
return false;
}
});
}
function un_like(id_artigo, id_user){
$.post('php/un_like.php', {artigo_id:id_artigo, user_id:id_user}, function(dados){
if(dados == 'sucesso'){
get_like(id_artigo);
}else{
return false;
}
});
function get_like(id_artigo){
$.post('php/get_like.php', {artigo_id:id_artigo}, function(valor){
$('#artigo'+id_artigo+'_like').text(valor);
});
}
</script>
<?php
**$selLikes verifica se existe o like**
$selLikes = getPhotoLiked($artigo_id, $user_id);
if($selLikes['num']==0){
echo'<a class="like" onclick="javascript:add_like('.$artigo_id.');this.disabled=true" href="javascript:void(0)">like</a>';
}elseif($selLikes['num']==1){
echo'<a class="unlike" onclick="javascript:un_like('.$artigo_id.', '.$user_id.')" href="javascript:void(0)">unlike</a>';
}
?>
We’re missing a
}
at the end offunction un_like(id_artigo, id_user){
, just to remember. See the console (F12) of the page. It would be better to create only one call to like/excuse, checking in the client-side whether or not it exists and removing or not.– Inkeliz
@Inkeliz is not possible to create a link that makes two functions I’m using onClick that calls different functions
– ndroid
The need is only to change the URL?
– Inkeliz
no @Inkeliz change anchor link <to> ex so the user likes the article he has the right to excuse but I want to do this without refresh on the page
– ndroid
Well, "change the like link to Unlike", in general you want to enjoy the function to be changed? If I like it now I will forgive? If this is it, there are better ways.
– Inkeliz
the same method that facebook uses like and slide
– ndroid