当我尝试设置我的请求标头令牌时,我收到一个错误:
ActionController::RoutingError (No route matches [OPTIONS] "/data"):
这是ajax调用:
$.ajax({
url: this.hostName + url,
type: 'POST',
data: data,
dataType: 'json',
beforeSend: function( xhr ) {
xhr.setRequestHeader( 'X-CSRF-Token', $( 'meta[name="csrf-token"]' ).attr( 'content' ) );
},
success: function(response) {
console.log('success');
console.log(response);
},
error: function(response) {
console.log('error');
console.log(response);
}
});
如果我将请求标头排除在外:
Started POST "/data" for 127.0.0.1 at 2012-07-24 18:37:22 -0700
但我收到一条警告:
WARNING: Can't verify CSRF token authenticity
关于为什么会发生这种情况的任何想法?