久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

    <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="qwawimqqmiuu" id='miuo0'><tfoot id='miuo0'></tfoot><dl id='miuo0'><fieldset id='miuo0'></fieldset></dl></div>

        如何在 Rails 4 應(yīng)用程序中啟用 CORS

        How to enable CORS in Rails 4 App(如何在 Rails 4 應(yīng)用程序中啟用 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="qwawimqqmiuu" id='6lopz'><tfoot id='6lopz'></tfoot><dl id='6lopz'><fieldset id='6lopz'></fieldset></dl></div>

                • 本文介紹了如何在 Rails 4 應(yīng)用程序中啟用 CORS的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

                  問(wèn)題描述

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

                  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();
                          }
                  

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

                  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?

                  目前我的控制器中有這個(gè):

                  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
                  

                  推薦答案

                  你應(yīng)該使用 rack cors

                  它提供了一個(gè)很好的 DSL,可以在你的 config/application.rb 中使用,而不是在過(guò)濾器之前使用凌亂的標(biāo)題.

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

                  一個(gè)非常寬松的方法如下,但當(dāng)然,你必須稍微調(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 應(yīng)用程序中啟用 CORS的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

                  相關(guān)文檔推薦

                  Is it possible for XHR HEAD requests to not follow redirects (301 302)(XHR HEAD 請(qǐng)求是否有可能不遵循重定向 (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?(如何修改另一個(gè)函數(shù)接收到的 XMLHttpRequest 響應(yīng)文本?)
                  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="qwawimqqmiuu" 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>
                            主站蜘蛛池模板: 国产乱人伦精品一区二区 | 久久国产精品视频 | 日韩久久网 | 日韩欧美一区在线 | 国产aa| 在线午夜 | 国产精品久久一区 | 国产小视频自拍 | 免费看国产片在线观看 | 伊人精品| 男人的天堂在线视频 | 国产91在线播放 | 国产亚洲精品91 | 国产高清在线观看 | 欧美日韩不卡在线 | 91在线观 | 色综合久久久 | 久久久久久久久91 | www.xxxx欧美| 亚洲综合婷婷 | 久久高清国产 | 久精品视频 | 日韩精品一区二区三区免费观看 | 亚洲午夜网 | 欧美男人天堂 | 日本欧美国产在线 | 欧美成人免费在线视频 | 国产精品久久久久久一区二区三区 | 国产精品美女视频 | 一区二区三区在线免费观看 | 国产精品久久久久aaaa九色 | a毛片| 欧美在线国产精品 | 国产精品1区2区3区 国产在线观看一区 | 91精品中文字幕一区二区三区 | 国产精品99久久久久久动医院 | 日一区二区 | 欧美综合视频 | 91精品国产乱码久久久久久 | 99久久精品国产一区二区三区 | 欧美一区2区三区4区公司 |