【发布时间】:2015-10-20 01:56:50
【问题描述】:
我在更新 html 文件中的 span 标签时遇到问题。我正在从服务器获取 JSON 对象,它也在 console.log 中显示。但是当我尝试在 AJAX:Success 中的 span 标签上更新它时,它不起作用。如果我在成功标签之外调用同一行,它确实在那里工作。
AJAX.JS
$('a.up_vote').click(function(e) {
e.preventDefault();
$(this).siblings("span").css( "background-color", "green" );
$.ajax({
url: $(this).attr('href'),
type :'get' ,
success : function (data){
$(this).find("span").css( "background-color", "red" );
$(this).siblings('span').html(data.count);
$(this).siblings("span").css( "background-color", "red" );
},
failure : function (data){
alert('failure') ;
}
}) ; // ajax call
}); // upvote link call
HTML
<div class ='up' style="float:left">
<a href='{% url 'upvote-detail' post.id %}' class='up_vote'>Up vote</a>
<span> {{ post.upvote }} </span>
</div>
【问题讨论】:
-
$(this) 里面的成功不是你想的那样……试试打印吧..
-
你也在使用 Angular JS 吗?
-
@Neron 我正在使用 DJANGO
-
请更新此线程,接受答案或通过评论或编辑提供详细信息,甚至自行回答为什么它不回答您的问题。
标签: javascript jquery ajax dom