2014-11-14 38 views
1

使用ajax編輯帖子時,瀏覽器出現錯誤。 XMLHttpRequest無法加載http://example.com/posts/100。 Access-Control-Allow-Methods不允許方法PUT。Access-Control-Allow-Methods不允許使用方法PUT

在軌服務器:

Started OPTIONS "/posts/100" for 127.0.0.1 at 2014-11-14 11:51:39 -0800 
    Processing by ApplicationController#handle_options_request as */* 
    Parameters: {"path"=>"posts/100"} 

我通過幾個解決方案去了,的確在rotues.rb像這樣 :在application_controller.rb

def handle_options_request 
    headers['Access-Control-Allow-Origin'] = request.env['HTTP_ORIGIN'] 
    headers['Access-Control-Allow-Methods'] = 'POST, GET, OPTIONS' 
    headers['Access-Control-Max-Age'] = '1000' 
    headers['Access-Control-Allow-Headers'] = '*,x-requested-with' 
    head(:ok) if request.request_method == "OPTIONS" 
    end 

任何

match '*path', :controller => 'application', :action => 'handle_options_request', :constraints => {:method => 'OPTIONS'} 

有解決方案來解決它。也可以嘗試架-CORS,但它不工作

回答

2

嘗試改變這一行(添加PUT):

headers['Access-Control-Allow-Methods'] = 'POST, GET, OPTIONS, PUT' 
相關問題