2011-12-18 101 views
0

如何在IE中使用XDomainRequest僞造PUT或DELETE請求?或者我需要使用iframe傳輸?Rails - 如何在IE中使用XDomainRequest僞造PUT或DELETE請求

我試圖訪問爲CORS設置的restful API。它適用於所有其他瀏覽器,但我無法弄清楚如何在IE中僞造PUT/DELETE動作。與XDomainRequest,custom headers are not allowed,所以我不能添加HTTP_X_HTTP_METHOD_OVERRIDE標題,據說這可以告訴Rails識別json數據中的_method=put參數。

回答

1

我能想到的最好的解決辦法是添加映射到#UPDATE兩個新成員的路線和#destroy:

resources :posts do 
    member do 
     post :revise, :action => :update 
     post :annihilate, :action => :destroy 
    end 
end 

當你運行「耙路線」,這添加了這些路線:

revise_post POST /posts/:id/revise(.:format)  {:action=>"update", :controller=>"posts"} 
annihilate_post POST /posts/:id/annihilate(.:format) {:action=>"destroy", :controller=>"posts"} 

注意,我本來想這:

resources :posts do 
    member do 
     post :update 
     post :destroy 
    end 
end 

希望它會創建這些路由:

update_post POST /posts/:id/update(.:format) {:action=>"update", :controller=>"posts"} 
destroy_post POST /posts/:id/destroy(.:format) {:action=>"destroy", :controller=>"posts"} 

而是它創造:

POST /posts/:id(.:format) {:action=>"update", :controller=>"posts"} 
POST /posts/:id(.:format) {:action=>"destroy", :controller=>"posts"} 

看起來像它們是重疊的,你永遠無法得到的帖子#摧毀。

相關問題