【发布时间】:2015-07-22 18:52:50
【问题描述】:
我有一个功能规范,作为页面加载的一部分。 我点击了一个本地网址以获取更多数据。
即使用http://fullcalendar.io/ 它通过 ajax 加载它的事件
events: {
url: 'calendar_events.json',
type: 'GET',
error: function(response) {
...
}},
我来了
XMLHttpRequest cannot load http://localhost:3000/calendar_events.json?start=2014-01-20&end=2014-01-27. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access. The response had HTTP status code 404.
不完全确定如何解决。我尝试添加
response.headers['Access-Control-Allow-Origin'] = '*'
response.headers['Access-Control-Allow-Methods'] = 'POST, PUT, DELETE, GET, OPTIONS'
response.headers['Access-Control-Request-Method'] = '*'
response.headers['Access-Control-Allow-Headers'] = 'Origin, X-Requested-With, Content-Type, Accept, Authorization'
到我的应用程序控制器上的 before_filter 只是为了查看,但仍然遇到同样的问题。
注意:我正在使用 capybara-webkit
【问题讨论】:
-
stackoverflow.com/a/6120260/3274024 你可以检查一下,也许这是请求的问题。
-
真的不想改成jsonp
-
也许跨域触发就够了。不知道我是否理解你为什么要访问本地 url,你能不能直接在服务器端渲染它?
标签: ruby-on-rails rspec capybara capybara-webkit