【发布时间】:2017-01-10 17:07:06
【问题描述】:
我在 VirtualBox(5.0.10) 上有 Ubuntu(64 位) 用于测试环境。当我尝试执行 Ajax 发布请求时,我得到“禁止(未设置 CSRF cookie。)”。
但我的 Web 应用程序中的相同发布操作在 OS X 的开发环境下运行良好。我怀疑这是新 Ubuntu 版本中的错误。
有人知道为什么会这样吗?
谢谢。
编辑:
$.ajax({
type: 'post',
url: '{% url 'add-new-watch-folder' %}',
data: {
dirs: dirsJSON,
csrfmiddlewaretoken: '{{ csrf_token }}'
},
dataType: 'text',
success: function(result){
console.log(result);
},
error: function(xhr, status, error){
console.log(error);
}
});
【问题讨论】:
-
您是否尝试过使用 postman 之类的插件来查看两台机器之间的差异?
-
这是一个简单的发布操作,所以我不需要。当我在测试环境中检查 cookie 时,我看到没有设置“csrftoken”和“sessionid”cookie。这其实就是区别。但不知道为什么。
-
请发布您的Ajax调用代码和获取CSRF令牌的功能
-
@Aison 编辑了我的问题。
标签: django cookies csrf ubuntu-16.04