【发布时间】:2020-10-29 05:42:41
【问题描述】:
我想喜欢或不喜欢一篇文章。我有一个实体 ArticleLike。 要注册“喜欢”,我在我的 ajax 中调用此函数:
url : '{{ path('post_like', {'id' : article.id, 'like' : 1}) }}'
但是当我喜欢时属性'like'是1,而当我不喜欢时属性'like'是0
我希望有 2 个按钮来调用这个 ajax 函数,并根据按钮调用向 ajax 函数发送 0 或 1
$(document).on('click', '#ajax', function(){
that = $(this);
$.ajax({
url : '{{ path('post_like', {'id' : article.id, 'like' : 1}) }}',
type : 'POST',
dataType : 'html',
success : function(code_html, statut){
code = JSON.parse(code_html);
$("a.likeChange").html(code.likes);
console.log(code_html)
},
error : function(resultat, statut, erreur){
}
});
return false;
});
【问题讨论】: