pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

    <bdo id='miuo0'></bdo><ul id='miuo0'></ul>

<small id='miuo0'></small><noframes id='miuo0'>

        <legend id='miuo0'><style id='miuo0'><dir id='miuo0'><q id='miuo0'></q></dir></style></legend>
      1. <tfoot id='miuo0'></tfoot>

      2. <i id='miuo0'><tr id='miuo0'><dt id='miuo0'><q id='miuo0'><span id='miuo0'><b id='miuo0'><form id='miuo0'><ins id='miuo0'></ins><ul id='miuo0'></ul><sub id='miuo0'></sub></form><legend id='miuo0'></legend><bdo id='miuo0'><pre id='miuo0'><center id='miuo0'></center></pre></bdo></b><th id='miuo0'></th></span></q></dt></tr></i><div class="3jjvjrl" id='miuo0'><tfoot id='miuo0'></tfoot><dl id='miuo0'><fieldset id='miuo0'></fieldset></dl></div>

        如何在 Rails 4 應用程序中啟用 CORS

        How to enable CORS in Rails 4 App(如何在 Rails 4 應用程序中啟用 CORS)

            <tbody id='6lopz'></tbody>

              <small id='6lopz'></small><noframes id='6lopz'>

              <legend id='6lopz'><style id='6lopz'><dir id='6lopz'><q id='6lopz'></q></dir></style></legend>

              <tfoot id='6lopz'></tfoot>
                • <bdo id='6lopz'></bdo><ul id='6lopz'></ul>
                  <i id='6lopz'><tr id='6lopz'><dt id='6lopz'><q id='6lopz'><span id='6lopz'><b id='6lopz'><form id='6lopz'><ins id='6lopz'></ins><ul id='6lopz'></ul><sub id='6lopz'></sub></form><legend id='6lopz'></legend><bdo id='6lopz'><pre id='6lopz'><center id='6lopz'></center></pre></bdo></b><th id='6lopz'></th></span></q></dt></tr></i><div class="ljxvbl1" id='6lopz'><tfoot id='6lopz'></tfoot><dl id='6lopz'><fieldset id='6lopz'></fieldset></dl></div>

                • 本文介紹了如何在 Rails 4 應用程序中啟用 CORS的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我正要拔掉頭發(fā)...從早上開始,我一直在嘗試在這個 Rails 應用程序中啟用 CORS,但它不起作用.我試過 this,使用 Rack Cors Gem, 這個答案和這個post都沒有成功.

                  I'm just about to pull my hair out... I've been trying to enable CORS in this Rails app since the morning and it just doesn't work. I've tried this, using Rack Cors Gem, this answer and this post all without success.

                  有人能指出正確的方向嗎?

                  Can someone point me in the right direction?

                  這是我的 js:

                        var req = new XMLHttpRequest();
                  
                        if ('withCredentials' in req) {
                              // req.open('GET', "https://api.github.com/users/mralexgray/repos", true);
                              req.open('GET', "http://www.postcoder.lc/postcodes/" + value, true);
                              // Just like regular ol' XHR
                              req.onreadystatechange = function() {
                                  if (req.readyState === 4) {
                                      if (req.status >= 200 && req.status < 400) {
                                          // JSON.parse(req.responseText) etc.
                                          console.log(req.responseText);
                                      } else {
                                          // Handle error case
                                      }
                                  }
                              };
                              req.send();
                          }
                  

                  當我嘗試這個網(wǎng)址時(來自外部客戶端):https://api.github.com/users/mralexgray/repos 工作正常,我假設(shè)問題出在我的 Rails API 上.我錯了嗎?

                  When I try this url (from an external client): https://api.github.com/users/mralexgray/repos that works ok, I'm assuming the problem is with my Rails API. Am I wrong?

                  目前我的控制器中有這個:

                  skip_before_filter :verify_authenticity_token
                  before_filter :cors_preflight_check
                  after_filter :cors_set_access_control_headers
                  
                  # For all responses in this controller, return the CORS access control headers.
                  def cors_set_access_control_headers
                    headers['Access-Control-Allow-Origin'] = '*'
                    headers['Access-Control-Allow-Methods'] = 'POST, GET, OPTIONS'
                    headers['Access-Control-Max-Age'] = "1728000"
                  end
                  
                  # If this is a preflight OPTIONS request, then short-circuit the
                  # request, return only the necessary headers and return an empty
                  # text/plain.
                  
                  def cors_preflight_check
                    headers['Access-Control-Allow-Origin'] = '*'
                    headers['Access-Control-Allow-Methods'] = 'POST, GET, OPTIONS'
                    headers['Access-Control-Allow-Headers'] = 'X-Requested-With, X-Prototype-Version'
                    headers['Access-Control-Max-Age'] = '1728000'
                  end
                  

                  推薦答案

                  你應該使用 rack cors

                  它提供了一個很好的 DSL,可以在你的 config/application.rb 中使用,而不是在過濾器之前使用凌亂的標題.

                  It provides a nice DSL, to use in your config/application.rb, instead of the messy header work and before filters.

                  一個非常寬松的方法如下,但當然,你必須稍微調(diào)整一下.

                  A very permissive would be as follows, but of course, you'll have to tailor it a bit.

                  use Rack::Cors do
                    allow do
                      origins '*'
                      resource '*', headers: :any, methods: :any
                    end  
                  end
                  

                  這篇關(guān)于如何在 Rails 4 應用程序中啟用 CORS的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                  【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

                  相關(guān)文檔推薦

                  Is it possible for XHR HEAD requests to not follow redirects (301 302)(XHR HEAD 請求是否有可能不遵循重定向 (301 302))
                  NETWORK_ERROR: XMLHttpRequest Exception 101(NETWORK_ERROR:XMLHttpRequest 異常 101)
                  XMLHttpRequest 206 Partial Content(XMLHttpRequest 206 部分內(nèi)容)
                  XmlHttpRequest onprogress interval(XmlHttpRequest onprogress 間隔)
                  How can I modify the XMLHttpRequest responsetext received by another function?(如何修改另一個函數(shù)接收到的 XMLHttpRequest 響應文本?)
                  What is the difference between XMLHttpRequest, jQuery.ajax, jQuery.post, jQuery.get(XMLHttpRequest、jQuery.ajax、jQuery.post、jQuery.get 有什么區(qū)別)
                • <tfoot id='324sp'></tfoot>

                        <small id='324sp'></small><noframes id='324sp'>

                          <tbody id='324sp'></tbody>
                          <i id='324sp'><tr id='324sp'><dt id='324sp'><q id='324sp'><span id='324sp'><b id='324sp'><form id='324sp'><ins id='324sp'></ins><ul id='324sp'></ul><sub id='324sp'></sub></form><legend id='324sp'></legend><bdo id='324sp'><pre id='324sp'><center id='324sp'></center></pre></bdo></b><th id='324sp'></th></span></q></dt></tr></i><div class="nllv1v9" id='324sp'><tfoot id='324sp'></tfoot><dl id='324sp'><fieldset id='324sp'></fieldset></dl></div>
                            <bdo id='324sp'></bdo><ul id='324sp'></ul>
                          • <legend id='324sp'><style id='324sp'><dir id='324sp'><q id='324sp'></q></dir></style></legend>
                            主站蜘蛛池模板: 综合管廊模具_生态,阶梯护坡模具_检查井模具制造-致宏模具厂家 | 北京网站建设公司_北京网站制作公司_北京网站设计公司-北京爱品特网站建站公司 | 自动气象站_农业气象站_超声波气象站_防爆气象站-山东万象环境科技有限公司 | Win10系统下载_32位/64位系统/专业版/纯净版下载 | 食品质构分析仪-氧化诱导分析仪-瞬态法导热系数仪|热冰百科 | 氧氮氢联合测定仪-联测仪-氧氮氢元素分析仪-江苏品彦光电 | 福建省教师资格证-福建教师资格证考试网| 口臭的治疗方法,口臭怎么办,怎么除口臭,口臭的原因-口臭治疗网 | 锂辉石检测仪器,水泥成分快速分析仪-湘潭宇科分析仪器有限公司 | 阿里巴巴诚信通温州、台州、宁波、嘉兴授权渠道商-浙江联欣科技提供阿里会员办理 | 重庆监控_电子围栏设备安装公司_门禁停车场管理系统-劲浪科技公司 | 大米加工设备|大米加工机械|碾米成套设备|大米加工成套设备-河南成立粮油机械有限公司 | 东莞市天进机械有限公司-钉箱机-粘箱机-糊箱机-打钉机认准东莞天进机械-厂家直供更放心! | 非标压力容器_碳钢储罐_不锈钢_搪玻璃反应釜厂家-山东首丰智能环保装备有限公司 | 上海办公室装修公司_办公室设计_直营办公装修-羚志悦装 | 电子万能试验机_液压拉力试验机_冲击疲劳试验机_材料试验机厂家-济南众标仪器设备有限公司 | 物和码官网,物和码,免费一物一码数字化营销SaaS平台 | 苏州西装定制-西服定制厂家-职业装定制厂家-尺品服饰西装定做公司 | 微妙网,专业的动画师、特效师、CG模型设计师网站! - wmiao.com 超声波电磁流量计-液位计-孔板流量计-料位计-江苏信仪自动化仪表有限公司 | 电伴热系统施工_仪表电伴热保温箱厂家_沃安电伴热管缆工业技术(济南)有限公司 | 沥青灌缝机_路面灌缝机_道路灌缝机_沥青灌缝机厂家_济宁萨奥机械有限公司 | 数码管_LED贴片灯_LED数码管厂家-无锡市冠卓电子科技有限公司 | 单级/双级旋片式真空泵厂家,2xz旋片真空泵-浙江台州求精真空泵有限公司 | 众品地板网-地板品牌招商_地板装修设计_地板门户的首选网络媒体。 | 烟气在线监测系统_烟气在线监测仪_扬尘检测仪_空气质量监测站「山东风途物联网」 | 爱德华真空泵油/罗茨泵维修,爱发科-比其尔产品供应东莞/杭州/上海等全国各地 | 北钻固控设备|石油钻采设备-石油固控设备厂家 | 球形钽粉_球形钨粉_纳米粉末_难熔金属粉末-广东银纳官网 | 美名宝起名网-在线宝宝、公司、起名平台 | 复合肥,化肥厂,复合肥批发,化肥代理,复合肥品牌-红四方 | 滚筒烘干机_转筒烘干机_滚筒干燥机_转筒干燥机_回转烘干机_回转干燥机-设备生产厂家 | 移动厕所租赁|移动卫生间|上海移动厕所租赁-家瑞租赁 | 礼堂椅厂家|佛山市艺典家具有限公司 | 污水处理设备维修_污水处理工程改造_机械格栅_过滤设备_气浮设备_刮吸泥机_污泥浓缩罐_污水处理设备_污水处理工程-北京龙泉新禹科技有限公司 | 立式壁挂广告机厂家-红外电容触摸一体机价格-华邦瀛 | HYDAC过滤器,HYDAC滤芯,现货ATOS油泵,ATOS比例阀-东莞市广联自动化科技有限公司 | 合肥网络推广_合肥SEO网站优化-安徽沃龙First | 辐射仪|辐射检测仪|辐射巡测仪|个人剂量报警仪|表面污染检测仪|辐射报警仪|辐射防护网 | 合肥废气治理设备_安徽除尘设备_工业废气处理设备厂家-盈凯环保 合肥防火门窗/隔断_合肥防火卷帘门厂家_安徽耐火窗_良万消防设备有限公司 | 防水套管厂家_刚性防水套管_柔性防水套管_不锈钢防水套管-郑州中泰管道 | 拖鞋定制厂家-品牌拖鞋代加工厂-振扬实业中国高端拖鞋大型制造商 |