当我在jquery中添加b标签(在html()中)时,出现HTTP/1.1 500 Internal Server Error [英] when I add b tag in jquery ( in html() ) I get HTTP/1.1 500 Internal Server Error
问题描述
这是代码
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');
}
})
});
一切正常,但是当我改变时:
every thing works fine but when I change :
<span class="glyphicon glyphicon-star"></span>like
to(在html和jquery文件中):
to (in both html and jquery files ):
<span class="glyphicon glyphicon-star"></span><b>like</b>
or
<b><span class="glyphicon glyphicon-star"></span>like</b>
这是在添加b标签之前发生的...一切都很好 屏幕截图1 添加b标签后屏幕截图2
this happens before adding b tag ... everything fine screen shot 1 after adding b tag screen shot 2
我收到此错误HTTP/1.1 500 Internal Server Error 并且我尝试了很多事情,但是jquery似乎不接受html()中的两个标签,原因是我尝试将b标签更改为span标签,并且出现了相同的错误,在此先感谢
I get this error HTTP/1.1 500 Internal Server Error and I tried many things but it seems that jquery doesn't accept two tags in html() cause I tried to change b tag to span tag and the same error appears and thanks in advance
推荐答案
尝试一下此代码段,类似于您的示例.
Try this snippet, similar to your example.
当您添加HTML时,无论其中包含多少标签,都不会发生. HTML应该是正确的,就是这样.
When you append an HTML, there is no matter how many tags you include in that. The HTML should be proper, That's it.
$('.like-post').click(function(){
$(event.target).html("<span class='glyphicon glyphicon-star'></span><b>like</b>");
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<a href="#" data-postid="105" data-userid="505" class="like-post">
Click
</a>
这篇关于当我在jquery中添加b标签(在html()中)时,出现HTTP/1.1 500 Internal Server Error的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!