Cookie不能处理从jQuery到Django的AJAX调用 [英] Cookies not working with an AJAX call from jQuery to Django
本文介绍了Cookie不能处理从jQuery到Django的AJAX调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个使用5星评级系统进行投票的Django网站(我使用 django-ratings
I have a Django site using a 5-star rating system for voting (I use django-ratings) and I would like to store the votings of the users with AJAX calls.
在客户端我有一个JavaScript函数发送一个GET请求到一个URL:
On the client side I have a JavaScript function sending a GET request to a URL:
$.ajax({
url: url,
success: function(data) {
alert('Load was performed.');
}
});
在服务器端我有设置cookie的代码:
On the server side I have code setting the cookie:
def vote(request, slug, rating):
# Some irrelevant code...
response = HttpResponse('Vote changed.')
response.set_cookie('vote', 123456)
return response
我做错了什么?
谢谢!
推荐答案
确定您的问题是关于跨站点请求伪造保护?大多数ajax请求拒绝django。您没有任何错误讯息吗?
Are sure that your problem is about Cross-site request forgery protection? most ajax requests rejected django by that. Don't you have any error messages?
这篇关于Cookie不能处理从jQuery到Django的AJAX调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文