我有一个功能规格说明,作为页面加载的一部分。我访问本地URL以获取更多数据。
例如,使用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。