【发布时间】:2014-02-24 09:41:29
【问题描述】:
所以我在forums.awake-gaming.com 上有一个应用程序,并在awake-gaming.com 上有一个页面,其中POST 通过ajax 向forums.awake-gaming.com 发送表单。
正如预期的那样,我得到了一个
XMLHttpRequest cannot load http://forums.awake-gaming.com/posts. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://awake-gaming.com' is therefore not allowed access.
因此,由于我可以访问服务器,因此我将其添加到 nginx/conf.d 目录下的 discourse.conf 文件中。
add_header Access-Control-Allow-Origin "http://awake-gaming.com/join-us.html";
add_header Access-Control-Allow-Methods: "GET, PUT, POST, DELETE, OPTIONS";
add_header Access-Control-Allow-Headers: "Content-Type, Authorization, X-Requested-With";
我重新启动了 nginx 并尝试再次提交表单,理论上,这应该可以工作,但我仍然在控制台中遇到同样的错误:
而且 ajax 调用也没有返回成功。但很奇怪,数据被发布到forums.awake-gaming.com 并被发布(通过话语 api)。
那我是不是错了?,我试图在 meta.discourse.org 上提问,但他们说这是 nginx 的问题,而不是话语的问题。在.conf 文件中添加标题是否足够?还是我也需要用 Rails 做点什么?
【问题讨论】: