當我嘗試設置我的請求頭的道理,我收到一個錯誤:路由錯誤:沒有路由匹配[OPTIONS]
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
任何想法,爲什麼發生這種情況?
不確定您的代碼的上下文,但認爲我指出[jquery-ujs](https://github.com/rails/jquery-ujs)你不知道它的情況,它適合你的需求。 – deefour 2012-07-25 03:41:37
你最終解決了這個問題嗎? – Ashitaka 2012-08-04 15:19:01
是啊@Ashitaka,看到接受的答案。 – 2012-09-09 01:14:39