【发布时间】:2016-06-09 02:23:15
【问题描述】:
我读到这两个基本上是同一件事,但每个都给我不同的错误,我不确定要追哪一个。我什至不知道如何解决这个问题。有人可以看看我的代码吗,我已经为此苦苦挣扎了两天。
我的html
<div id='notificationsLoader'>
</div>
<script>
$(document).ready(function(){
$(".notification-toggle").click(function(e){
e.preventDefault();
$.ajax({
type:"POST",
url:"{% url 'get_notifications_ajax' %}",
data: {
csrfmiddlewaretoken:"{%csrf_token%}",
},
success: function(data){
$("#notificationsLoader").html('<h3>notifications</h3>');
$(data.notifications).each(function(){
$("notificationsLoader").append(this + "<br/>")
})
console.log(data.notifications);
},
error: function(rs, e){
console.log(rs);
console.log(e);
}
})
})
})
</script>
其他html
<li><a class="notification-toggle" href="#">notification</a></li>
通知来自我的 python 代码
@login_required
def get_notifications_ajax(request):
notification = Notification.objects.get(id=id)
notes =[]
for note in notifications:
notes.append(str(note))
data={
"notifications":notes
}
json_data = json.dumps(data)
return HttpResponse(json_data, content_type='application/json')
还有更多内容,但我只发布这部分,因为我认为错误(403 和 500)是说我的服务器端错误
【问题讨论】:
标签: javascript jquery python django