Cookie 不适用于从 jQuery 到 Django 的 AJAX 调用
我有一个 Django 网站,使用 5 星级评级系统进行投票(我使用 django- ratings)我想通过 AJAX 调用存储用户的投票。
在客户端,我有一个 JavaScript 函数,向 URL 发送 GET 请求:
$.ajax({
url: url,
success: function(data) {
alert('Load was performed.');
}
});
在服务器端,我有设置 cookie 的代码:
def vote(request, slug, rating):
# Some irrelevant code...
response = HttpResponse('Vote changed.')
response.set_cookie('vote', 123456)
return response
问题是 cookie 从未在浏览器中设置。
我做错了什么?
谢谢!
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.
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.');
}
});
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
The problem is that the cookie is never set in the browser.
What I am doing wrong?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
确定您的问题与跨站点请求伪造保护有关吗?大多数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?