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

  • <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="wyu60wa" 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="wwu2cqk" 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="aowyuma" 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>
                          • 主站蜘蛛池模板: 石磨面粉机|石磨面粉机械|石磨面粉机组|石磨面粉成套设备-河南成立粮油机械有限公司 | 全国国际学校排名_国际学校招生入学及学费-学校大全网 | 合肥白癜风医院_[治疗白癜风]哪家好_合肥北大白癜风医院 | 不锈钢水箱生产厂家_消防水箱生产厂家-河南联固供水设备有限公司 | 抓斗式清污机|螺杆式|卷扬式启闭机|底轴驱动钢坝|污水处理闸门-方源水利机械 | 河南档案架,档案密集架,手动密集架,河南密集架批发/报价 | (中山|佛山|江门)环氧地坪漆,停车场地板漆,车库地板漆,聚氨酯地板漆-中山永旺地坪漆厂家 | 苏商学院官网 - 江苏地区唯一一家企业家自办的前瞻型、实操型商学院 | 百方网-百方电气网,电工电气行业专业的B2B电子商务平台 | 芜湖厨房设备_芜湖商用厨具_芜湖厨具设备-芜湖鑫环厨具有限公司 控显科技 - 工控一体机、工业显示器、工业平板电脑源头厂家 | 洁净棚-洁净工作棚-无菌室-净化工程公司_北京卫护科技有限公司 | 阜阳成人高考_阜阳成考报名时间_安徽省成人高考网 | 对辊破碎机_四辊破碎机_双齿辊破碎机_华盛铭重工 | 服务器之家 - 专注于服务器技术及软件下载分享 | Pos机办理_个人商户免费POS机申请-拉卡拉办理网 | 神马影院-实时更新秒播| 衡阳耐适防护科技有限公司——威仕盾焊接防护用品官网/焊工手套/焊接防护服/皮革防护手套 | 上海办公室装修_上海店铺装修公司_厂房装潢设计_办公室装修 | 丹佛斯变频器-Danfoss战略代理经销商-上海津信变频器有限公司 | 电动打包机_气动打包机_钢带捆扎机_废纸打包机_手动捆扎机 | 纯水设备_苏州皙全超纯水设备水处理设备生产厂家 | 今日娱乐圈——影视剧集_八卦娱乐_明星八卦_最新娱乐八卦新闻 | 5L旋转蒸发器-20L-50L旋转蒸发器-上海越众仪器设备有限公司 | 济南货架定做_仓储货架生产厂_重型货架厂_仓库货架批发_济南启力仓储设备有限公司 | 杭州厂房降温,车间降温设备,车间通风降温,厂房降温方案,杭州嘉友实业爽风品牌 | 深圳VI设计-画册设计-LOGO设计-包装设计-品牌策划公司-[智睿画册设计公司] | 电动高尔夫球车|电动观光车|电动巡逻车|电动越野车厂家-绿友机械集团股份有限公司 | 国际线缆连接网 - 连接器_线缆线束加工行业门户网站 | 上海小程序开发-小程序制作-上海小程序定制开发公司-微信商城小程序-上海咏熠 | 北京西风东韵品牌与包装设计公司,创造视觉销售力!| 石油/泥浆/不锈钢防腐/砂泵/抽砂泵/砂砾泵/吸砂泵/压滤机泵 - 专业石油环保专用泵厂家 | 400电话_400电话申请_888元包年_400电话办理服务中心_400VIP网 | 变频器维修公司_plc维修_伺服驱动器维修_工控机维修 - 夫唯科技 变位机,焊接变位机,焊接变位器,小型变位机,小型焊接变位机-济南上弘机电设备有限公司 | 聚氨酯复合板保温板厂家_廊坊华宇创新科技有限公司 | 杰恒蠕动泵-蠕动泵专业厂家-19年专注蠕动泵 | 电动车头盔厂家_赠品头盔_安全帽批发_山东摩托车头盔—临沂承福头盔 | 移动厕所租赁|移动卫生间|上海移动厕所租赁-家瑞租赁 | 欧必特空气能-商用空气能热水工程,空气能热水器,超低温空气源热泵生产厂家-湖南欧必特空气能公司 | 济南品牌包装设计公司_济南VI标志设计公司_山东锐尚文化传播 | 钢衬玻璃厂家,钢衬玻璃管道 -山东东兴扬防腐设备有限公司 | ZHZ8耐压测试仪-上海胜绪电气有限公司 |