【发布时间】:2016-09-13 08:50:01
【问题描述】:
这是代码
html
<a href="#" data-postid="{{ $post->id }}" data-userid="{{ Auth::user()->id }}" class="like-post">
@if(Auth::user()->likes()->where(['user_id' => Auth::user()->id, 'post_or_comment_id' => $post->id,'isPost' => 1])->first())
<span class="glyphicon glyphicon-star"></span>like
@else
<span class="glyphicon glyphicon-star-empty"></span>like
@endif
</a>|
jquery
$('.like-post').on('click',function(event){
event.preventDefault();
var userId = event.target.dataset['userid'];
var postId = event.target.dataset['postid'];
$.ajax({
method:'POST',
url:likeUrl,
data:{userId:userId, p_or_c:postId, isPost:1, _token:token},
success:function(msg){
if(msg['like'] == 0)
$(event.target).html('<span class="glyphicon glyphicon-star-empty"></span>like');
else
$(event.target).html('<span class="glyphicon glyphicon-star"></span>like');
console.log(msg['like']+'yes');
}
})
});
一切正常,但当我改变时:
<span class="glyphicon glyphicon-star"></span>like
到(在 html 和 jquery 文件中):
<span class="glyphicon glyphicon-star"></span><b>like</b>
or
<b><span class="glyphicon glyphicon-star"></span>like</b>
这发生在添加 b 标签之前......一切都很好 screen shot 1 添加b标签后screen shot 2
我收到此错误 HTTP/1.1 500 Internal Server Error 我尝试了很多东西,但似乎 jquery 不接受 html() 中的两个标签,因为我试图将 b 标签更改为 span 标签,并且出现相同的错误并提前感谢
【问题讨论】:
-
你也可以使用标签代替
-
我做了同样的事情
-
请您尝试只放置带有 标记的文本内容,然后检查是什么问题?
-
这可能与你的 if else 子句有关,尝试强制它为真或假,也许你的类“-empty 没有”加载或什么
-
我做了 like .....同样的错误