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

  • <i id='Q1l9Z'><tr id='Q1l9Z'><dt id='Q1l9Z'><q id='Q1l9Z'><span id='Q1l9Z'><b id='Q1l9Z'><form id='Q1l9Z'><ins id='Q1l9Z'></ins><ul id='Q1l9Z'></ul><sub id='Q1l9Z'></sub></form><legend id='Q1l9Z'></legend><bdo id='Q1l9Z'><pre id='Q1l9Z'><center id='Q1l9Z'></center></pre></bdo></b><th id='Q1l9Z'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='Q1l9Z'><tfoot id='Q1l9Z'></tfoot><dl id='Q1l9Z'><fieldset id='Q1l9Z'></fieldset></dl></div>
    1. <tfoot id='Q1l9Z'></tfoot>
    2. <small id='Q1l9Z'></small><noframes id='Q1l9Z'>

        <legend id='Q1l9Z'><style id='Q1l9Z'><dir id='Q1l9Z'><q id='Q1l9Z'></q></dir></style></legend>
          <bdo id='Q1l9Z'></bdo><ul id='Q1l9Z'></ul>

        JavaScript - XMLHttpRequest、Access-Control-Allow-Origin 錯誤

        JavaScript - XMLHttpRequest, Access-Control-Allow-Origin errors(JavaScript - XMLHttpRequest、Access-Control-Allow-Origin 錯誤)

          <tbody id='UDyOS'></tbody>
        1. <i id='UDyOS'><tr id='UDyOS'><dt id='UDyOS'><q id='UDyOS'><span id='UDyOS'><b id='UDyOS'><form id='UDyOS'><ins id='UDyOS'></ins><ul id='UDyOS'></ul><sub id='UDyOS'></sub></form><legend id='UDyOS'></legend><bdo id='UDyOS'><pre id='UDyOS'><center id='UDyOS'></center></pre></bdo></b><th id='UDyOS'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='UDyOS'><tfoot id='UDyOS'></tfoot><dl id='UDyOS'><fieldset id='UDyOS'></fieldset></dl></div>

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

          <legend id='UDyOS'><style id='UDyOS'><dir id='UDyOS'><q id='UDyOS'></q></dir></style></legend>
              • <tfoot id='UDyOS'></tfoot>
                  <bdo id='UDyOS'></bdo><ul id='UDyOS'></ul>
                  本文介紹了JavaScript - XMLHttpRequest、Access-Control-Allow-Origin 錯誤的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我正在嘗試將 XMLHttpRequest 發送到粘貼站點.我正在發送一個包含 api 需要的所有字段的對象,但我一直遇到這個問題.我已經閱讀了這個問題,我想:

                  I'm attempting to send a XMLHttpRequest to a paste site. I'm sending an object containing all the fields that the api requires, but I keep getting this issue. I have read over the issue, and I thought:

                  httpReq.setRequestHeader('Access-Control-Allow-Headers', '*');
                  

                  會修復它,但它沒有.有沒有人有關于這個錯誤的任何信息和/或我如何解決它?

                  Would fix it,but it didn't. Does anyone have any information on this error and/or how I can fix it?

                  這是我的代碼:

                  (function () {
                  
                      'use strict';
                  
                      var httpReq = new XMLHttpRequest();
                      var url = 'http://paste.ee/api';
                      var fields = 'key=public&description=test&paste=this is a test paste&format=JSON';
                      var fields2 = {key: 'public', description: 'test', paste: 'this is a test paste', format: 'JSON'};
                  
                      httpReq.open('POST', url, true);
                      console.log('good');
                  
                      httpReq.setRequestHeader('Access-Control-Allow-Headers', '*');
                      httpReq.setRequestHeader('Content-type', 'application/ecmascript');
                      httpReq.setRequestHeader('Access-Control-Allow-Origin', '*');
                      console.log('ok');
                  
                      httpReq.onreadystatechange = function () {
                          console.log('test');
                          if (httpReq.readyState === 4 && httpReq.status === 'success') {
                              console.log('test');
                              alert(httpReq.responseText);
                          }
                      };
                  
                      httpReq.send(fields2);
                  
                  }());
                  

                  這是確切的控制臺輸出:

                  And here is the exact console output:

                  good
                  ok
                  Failed to load resource: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://127.0.0.1:40217' is therefore not allowed access. http://paste.ee/api
                  XMLHttpRequest cannot load http://paste.ee/api. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://127.0.0.1:40217' is therefore not allowed access. index.html:1
                  test
                  

                  這是我在常規 Chromium 瀏覽器上本地測試時的控制臺輸出:

                  Here is the console output when I test it locally on a regular Chromium browser:

                  good
                  ok
                  XMLHttpRequest cannot load http://paste.ee/api. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access. index.html:1
                  test
                  

                  推薦答案

                  我認為你錯過了訪問控制這一點.

                  I think you've missed the point of access control.

                  快速回顧一下 CORS 存在的原因:由于來自網站的 JS 代碼可以執行 XHR,因此該網站可能會向其他網站發送請求,偽裝成您并利用 那些網站對您的信任(例如,如果您已登錄,惡意站點可能會嘗試提取信息或執行您從未想要的操作) - 這稱為 CSRF 攻擊.為了防止這種情況發生,網絡瀏覽器對您可以發送的 XHR 有非常嚴格的限制——您通常僅限于您的域,等等.

                  A quick recap on why CORS exists: Since JS code from a website can execute XHR, that site could potentially send requests to other sites, masquerading as you and exploiting the trust those sites have in you(e.g. if you have logged in, a malicious site could attempt to extract information or execute actions you never wanted) - this is called a CSRF attack. To prevent that, web browsers have very stringent limitations on what XHR you can send - you are generally limited to just your domain, and so on.

                  現在,有時網站允許其他網站與其聯系很有用 - 提供 API 或服務的網站(例如您嘗試訪問的網站)將是主要候選者.開發 CORS 是為了允許站點 A(例如 paste.ee)說我信任站點 B,因此您可以將 XHR 從它發送給我".這是由站點 A 在其響應中發送Access-Control-Allow-Origin"標頭指定的.

                  Now, sometimes it's useful for a site to allow other sites to contact it - sites that provide APIs or services, like the one you're trying to access, would be prime candidates. CORS was developed to allow site A(e.g. paste.ee) to say "I trust site B, so you can send XHR from it to me". This is specified by site A sending "Access-Control-Allow-Origin" headers in its responses.

                  在您的具體情況下,似乎 paste.ee 并不費心使用 CORS.如果您想在瀏覽器腳本中使用 paste.ee,最好的辦法是聯系網站所有者并找出原因.或者,您可以嘗試使用擴展程序(應該具有更高的 XHR 權限).

                  In your specific case, it seems that paste.ee doesn't bother to use CORS. Your best bet is to contact the site owner and find out why, if you want to use paste.ee with a browser script. Alternatively, you could try using an extension(those should have higher XHR privileges).

                  這篇關于JavaScript - XMLHttpRequest、Access-Control-Allow-Origin 錯誤的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

                  相關文檔推薦

                  Browser waits for ajax call to complete even after abort has been called (jQuery)(即使在調用 abort (jQuery) 之后,瀏覽器也會等待 ajax 調用完成)
                  JavaScript innerHTML is not working for IE?(JavaScript innerHTML 不適用于 IE?)
                  XMLHttpRequest cannot load, No #39;Access-Control-Allow-Origin#39; header is present on the requested resource(XMLHttpRequest 無法加載,請求的資源上不存在“Access-Control-Allow-Origin標頭) - IT屋-程序員軟件開發技術分
                  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 部分內容)

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

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

                          • <bdo id='zLDgL'></bdo><ul id='zLDgL'></ul>
                          • 主站蜘蛛池模板: 香蕉久久久 | 久久久久久国产精品 | 久久精品小视频 | 欧美aaaa视频 | 粉嫩高清一区二区三区 | 国产男女猛烈无遮掩视频免费网站 | 日韩精品在线一区二区 | 午夜视频免费网站 | www.精品一区 | 免费黄色成人 | 日本人做爰大片免费观看一老师 | 精品国产欧美 | jizz中国日本 | 97影院2| 亚洲欧美日韩精品久久亚洲区 | 精精国产xxxx视频在线播放 | 色狠狠一区 | 日韩一区二区在线观看视频 | 成人精品一区 | 久草中文在线 | 久久中文字幕一区 | 久久精品一区 | 色视频www在线播放国产人成 | 国产午夜精品一区二区三区在线观看 | 免费福利视频一区二区三区 | 亚洲黄色一级 | 亚洲精品一区二区在线观看 | 午夜视频在线 | 久久免费视频在线 | 日本久久精品视频 | 91影库| 一区二区中文字幕 | 91秦先生艺校小琴 | 在线成人av | 国产蜜臀 | 九九综合九九 | 欧美精品久久久久久久久久 | 99热精品久久 | 午夜激情视频在线 | 亚洲bt 欧美bt 日本bt | 美女黄频|