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

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

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

        <tfoot id='QSfLR'></tfoot>

        <legend id='QSfLR'><style id='QSfLR'><dir id='QSfLR'><q id='QSfLR'></q></dir></style></legend>
        <i id='QSfLR'><tr id='QSfLR'><dt id='QSfLR'><q id='QSfLR'><span id='QSfLR'><b id='QSfLR'><form id='QSfLR'><ins id='QSfLR'></ins><ul id='QSfLR'></ul><sub id='QSfLR'></sub></form><legend id='QSfLR'></legend><bdo id='QSfLR'><pre id='QSfLR'><center id='QSfLR'></center></pre></bdo></b><th id='QSfLR'></th></span></q></dt></tr></i><div class="tjb9ftd" id='QSfLR'><tfoot id='QSfLR'></tfoot><dl id='QSfLR'><fieldset id='QSfLR'></fieldset></dl></div>
      1. AJAX 請(qǐng)求獲取“請(qǐng)求的資源上不存在‘Access-Cont

        AJAX request gets quot;No #39;Access-Control-Allow-Origin#39; header is present on the requested resourcequot; error(AJAX 請(qǐng)求獲取“請(qǐng)求的資源上不存在‘Access-Control-Allow-Origin’標(biāo)頭;錯(cuò)誤) - IT屋-程序員軟件開(kāi)發(fā)

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

      2. <small id='PvrMh'></small><noframes id='PvrMh'>

          • <tfoot id='PvrMh'></tfoot>
            <legend id='PvrMh'><style id='PvrMh'><dir id='PvrMh'><q id='PvrMh'></q></dir></style></legend>

                  <tbody id='PvrMh'></tbody>
                • <bdo id='PvrMh'></bdo><ul id='PvrMh'></ul>
                  本文介紹了AJAX 請(qǐng)求獲取“請(qǐng)求的資源上不存在‘Access-Control-Allow-Origin’標(biāo)頭";錯(cuò)誤的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

                  問(wèn)題描述

                  我嘗試在 jQuery AJAX 請(qǐng)求中發(fā)送 GET 請(qǐng)求.

                  I attempt to send a GET request in a jQuery AJAX request.

                  $.ajax({
                      type: 'GET',
                      url: /* <the link as string> */,
                      dataType: 'text/html',
                      success: function() { alert("Success"); },
                      error: function() { alert("Error"); },
                  });
                  

                  但是,無(wú)論我嘗試過(guò)什么,我都得到 XMLHttpRequest 無(wú)法加載 <page>.請(qǐng)求的資源上不存在Access-Control-Allow-Origin"標(biāo)頭.因此不允許訪問(wèn) Origin 'http://localhost:7776'.

                  However, whatever I've tried, I got XMLHttpRequest cannot load <page>. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:7776' is therefore not allowed access.

                  我嘗試了所有方法,從將 header : {} 定義添加到 AJAX 請(qǐng)求到將 dataType 設(shè)置為 JSONP,甚至是 text/plain,使用簡(jiǎn)單的 AJAX 而不是 jQuery,甚至下載啟用 CORS 的插件 - 但沒(méi)有任何幫助.

                  I tried everything, from adding header : {} definitions to the AJAX request to setting dataType to JSONP, or even text/plain, using simple AJAX instead of jQuery, even downloading a plugin that enables CORS - but nothing could help.

                  如果我嘗試訪問(wèn)任何其他網(wǎng)站,也會(huì)發(fā)生同樣的情況.

                  And the same happens if I attempt to reach any other sites.

                  對(duì)于適當(dāng)且簡(jiǎn)單的解決方案有任何想法嗎?有嗎?

                  Any ideas for a proper and simple solution? Is there any at all?

                  推薦答案

                  這是設(shè)計(jì)使然.您不能使用 XMLHttpRequest 向另一臺(tái)服務(wù)器發(fā)出任意 HTTP 請(qǐng)求,除非該服務(wù)器通過(guò)為請(qǐng)求主機(jī)提供 Access-Control-Allow-Origin 標(biāo)頭來(lái)允許它.

                  This is by design. You can't make an arbitrary HTTP request to another server using XMLHttpRequest unless that server allows it by putting out an Access-Control-Allow-Origin header for the requesting host.

                  https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS

                  您可以在腳本標(biāo)簽中檢索它(對(duì)腳本、圖像和樣式表沒(méi)有相同的限制),但除非返回的內(nèi)容是腳本,否則對(duì)您沒(méi)有多大用處.

                  You could retrieve it in a script tag (there isn't the same restriction on scripts and images and stylesheets), but unless the content returned is a script, it won't do you much good.

                  這里有一個(gè)關(guān)于 CORS 的教程:

                  Here's a tutorial on CORS:

                  http://www.bennadel.com/blog/2327-cross-origin-resource-sharing-cors-ajax-requests-between-jquery-and-node-js.htm

                  這一切都是為了保護(hù)最終用戶.假設(shè)圖像實(shí)際上是圖像,樣式表只是樣式表,腳本只是腳本,從另一臺(tái)服務(wù)器請(qǐng)求這些資源不會(huì)真正造成任何傷害.

                  This is all done to protect the end user. Assuming that an image is actually an image, a stylesheet is just a stylesheet and a script is just a script, requesting those resources from another server can't really do any harm.

                  但總的來(lái)說(shuō),跨域請(qǐng)求可能會(huì)做一些非常糟糕的事情.假設(shè)您,Zoltan,正在使用coolsharks.com.還要說(shuō)您已登錄 mybank.com,并且您的瀏覽器中有一個(gè) mybank.com 的 cookie.現(xiàn)在,假設(shè)coolsharks.com 向mybank.com 發(fā)送了一個(gè)AJAX 請(qǐng)求,要求將您的所有資金轉(zhuǎn)入另一個(gè)帳戶.因?yàn)槟鎯?chǔ)了 mybank.com cookie,所以他們成功完成了請(qǐng)求.所有這一切都是在您不知情的情況下發(fā)生的,因?yàn)闆](méi)有發(fā)生頁(yè)面重新加載.這是允許一般跨站點(diǎn) AJAX 請(qǐng)求的危險(xiǎn).

                  But in general, cross-origin requests can do really bad things. Say that you, Zoltan, are using coolsharks.com. Say also that you are logged into mybank.com and there is a cookie for mybank.com in your browser. Now, suppose that coolsharks.com sends an AJAX request to mybank.com, asking to transfer all your money into another account. Because you have a mybank.com cookie stored, they successfully complete the request. And all of this happens without your knowledge, because no page reload occurred. This is the danger of allowing general cross-site AJAX requests.

                  如果要執(zhí)行跨站請(qǐng)求,有兩種選擇:

                  If you want to perform cross-site requests, you have two options:

                  1. 將您發(fā)出請(qǐng)求的服務(wù)器獲取到
                    一個(gè).通過(guò)發(fā)布包含您(或 *)的 Access-Control-Allow-Origin 標(biāo)頭來(lái)承認(rèn)您
                    灣.為您提供 JSONP API.

                  1. 編寫(xiě)自己的瀏覽器,不遵循標(biāo)準(zhǔn),沒(méi)有限制.

                  在 (1) 中,您必須與您正在向其發(fā)出請(qǐng)求的服務(wù)器合作,并且在 (2) 中,您必須能夠控制最終用戶的瀏覽器.如果你不能滿足 (1) 或 (2),那你就很不走運(yùn)了.

                  In (1), you must have the cooperation of the server you are making requests to, and in (2), you must have control over the end user's browser. If you can't fulfill (1) or (2), you're pretty much out of luck.

                  但是,還有第三種選擇(charlietfl 指出).您可以從您控制的服務(wù)器發(fā)出請(qǐng)求,然后將結(jié)果傳回您的頁(yè)面.例如

                  However, there is a third option (pointed out by charlietfl). You can make the request from a server that you do control and then pass the result back to your page. E.g.

                  <script>
                  $.ajax({
                      type: 'GET',
                      url: '/proxyAjax.php?url=http%3A%2F%2Fstackoverflow.com%2F10m',
                      dataType: 'text/html',
                      success: function() { alert("Success"); },
                      error: function() { alert("Error"); }
                  });
                  </script>
                  

                  然后在您的服務(wù)器上,最簡(jiǎn)單:

                  And then on your server, at its most simple:

                  <?php
                  // proxyAjax.php
                  // ... validation of params
                  // and checking of url against whitelist would happen here ...
                  // assume that $url now contains "http://stackoverflow.com/10m"
                  echo file_get_contents($url);
                  

                  當(dāng)然,這種方法可能會(huì)遇到其他問(wèn)題:

                  Of course, this method may run into other issues:

                  • 您作為代理的網(wǎng)站是否需要正確的引薦來(lái)源網(wǎng)址或特定 IP 地址?
                  • 是否需要將 cookie 傳遞到目標(biāo)服務(wù)器?
                  • 您的白名單是否足以保護(hù)您免于提出任意請(qǐng)求?
                  • 當(dāng)您的服務(wù)器收到它們時(shí),您會(huì)將哪些標(biāo)頭(例如修改時(shí)間等)傳遞回瀏覽器,您會(huì)忽略或更改哪些標(biāo)頭?
                  • 您的服務(wù)器是否會(huì)被牽連提出非法請(qǐng)求(因?yàn)槟谴??

                  我確定還有其他人.但是,如果這些問(wèn)題都沒(méi)有阻止它,那么第三種方法可以很好地工作.

                  I'm sure there are others. But if none of those issues prevent it, this third method could work quite well.

                  這篇關(guān)于AJAX 請(qǐng)求獲取“請(qǐng)求的資源上不存在‘Access-Control-Allow-Origin’標(biāo)頭";錯(cuò)誤的文章就介紹到這了,希望我們推薦的答案對(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)文檔推薦

                  Browser waits for ajax call to complete even after abort has been called (jQuery)(即使在調(diào)用 abort (jQuery) 之后,瀏覽器也會(huì)等待 ajax 調(diào)用完成)
                  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 無(wú)法加載,請(qǐng)求的資源上不存在“Access-Control-Allow-Origin標(biāo)頭) - IT屋-程序員軟件開(kāi)發(fā)技術(shù)分
                  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)容)
                    <i id='r6Y5P'><tr id='r6Y5P'><dt id='r6Y5P'><q id='r6Y5P'><span id='r6Y5P'><b id='r6Y5P'><form id='r6Y5P'><ins id='r6Y5P'></ins><ul id='r6Y5P'></ul><sub id='r6Y5P'></sub></form><legend id='r6Y5P'></legend><bdo id='r6Y5P'><pre id='r6Y5P'><center id='r6Y5P'></center></pre></bdo></b><th id='r6Y5P'></th></span></q></dt></tr></i><div class="n09dvbw" id='r6Y5P'><tfoot id='r6Y5P'></tfoot><dl id='r6Y5P'><fieldset id='r6Y5P'></fieldset></dl></div>

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

                        <tbody id='r6Y5P'></tbody>

                        <bdo id='r6Y5P'></bdo><ul id='r6Y5P'></ul>
                        <tfoot id='r6Y5P'></tfoot>

                          • <legend id='r6Y5P'><style id='r6Y5P'><dir id='r6Y5P'><q id='r6Y5P'></q></dir></style></legend>

                          • 主站蜘蛛池模板: 工业插头-工业插头插座【厂家】-温州罗曼电气 | 成都竞价托管_抖音代运营_网站建设_成都SEM外包-成都智网创联网络科技有限公司 | 定做大型恒温循环水浴槽-工业用不锈钢恒温水箱-大容量低温恒温水槽-常州精达仪器 | 散热器-电子散热器-型材散热器-电源散热片-镇江新区宏图电子散热片厂家 | 拉曼光谱仪_便携式|激光|显微共焦拉曼光谱仪-北京卓立汉光仪器有限公司 | 交变/复合盐雾试验箱-高低温冲击试验箱_安奈设备产品供应杭州/江苏南京/安徽马鞍山合肥等全国各地 | 中国玩具展_玩具展|幼教用品展|幼教展|幼教装备展 | 专业的新乡振动筛厂家-振动筛品质保障-环保振动筛价格—新乡市德科筛分机械有限公司 | 清水混凝土修复_混凝土色差修复剂_混凝土色差调整剂_清水混凝土色差修复_河南天工 | 中视电广_短视频拍摄_短视频推广_短视频代运营_宣传片拍摄_影视广告制作_中视电广 | 丝印油墨_水性油墨_环保油墨油漆厂家_37国际化工 | 天津仓库出租网-天津电商仓库-天津云仓一件代发-【博程云仓】 | 网站建设_网站制作_SEO优化推广_百度推广开户_朋友圈网络科技 | 臻知网大型互动问答社区-你的问题将在这里得到解答!-无锡据风网络科技有限公司 | 硬度计_影像测量仪_维氏硬度计_佛山市精测计量仪器设备有限公司厂家 | vr安全体验馆|交通安全|工地安全|禁毒|消防|安全教育体验馆|安全体验教室-贝森德(深圳)科技 | 进口试验机价格-进口生物材料试验机-西安卡夫曼测控技术有限公司 | 镀锌钢格栅_热镀锌格栅板_钢格栅板_热镀锌钢格板-安平县昊泽丝网制品有限公司 | 行星齿轮减速机,减速机厂家,山东减速机-淄博兴江机械制造 | 厦门ISO认证|厦门ISO9001认证|厦门ISO14001认证|厦门ISO45001认证-艾索咨询专注ISO认证行业 | 选矿设备-新型重选设备-金属矿尾矿重选-青州冠诚重工机械有限公司 | 海南在线 海南一家| 云南成人高考_云南成考网| 天空彩票天下彩,天空彩天空彩票免费资料,天空彩票与你同行开奖,天下彩正版资料大全 | 注塑_注塑加工_注塑模具_塑胶模具_注塑加工厂家_深圳环科 | 解放卡车|出口|济南重汽|报价大全|山东三维商贸有限公司 | 冷却塔减速机器_冷却塔皮带箱维修厂家_凉水塔风机电机更换-广东康明冷却塔厂家 | 知网论文检测系统入口_论文查重免费查重_中国知网论文查询_学术不端检测系统 | 激光内雕_led玻璃_发光玻璃_内雕玻璃_导光玻璃-石家庄明晨三维科技有限公司 激光内雕-内雕玻璃-发光玻璃 | 企业微信scrm管理系统_客户关系管理平台_私域流量运营工具_CRM、ERP、OA软件-腾辉网络 | 三价铬_环保铬_环保电镀_东莞共盈新材料贸易有限公司 | 伟秀电气有限公司-10kv高低压开关柜-高低压配电柜-中置柜-充气柜-欧式箱变-高压真空断路器厂家 | 香港新时代国际美容美发化妆美甲培训学校-26年培训经验,值得信赖! | 液压扳手-高品质液压扳手供应商 - 液压扳手, 液压扳手供应商, 德国进口液压拉马 | 华禹护栏|锌钢护栏_阳台护栏_护栏厂家-华禹专注阳台护栏、楼梯栏杆、百叶窗、空调架、基坑护栏、道路护栏等锌钢护栏产品的生产销售。 | 影像测量仪_三坐标测量机_一键式二次元_全自动影像测量仪-广东妙机精密科技股份有限公司 | 卷筒电缆-拖链电缆-特种柔性扁平电缆定制厂家「上海缆胜」 | 合肥办公室装修 - 合肥工装公司 - 天思装饰 | LINK FASHION 童装·青少年装展| 垃圾清运公司_环卫保洁公司_市政道路保洁公司-华富环境 | 伸缩器_伸缩接头_传力接头-巩义市润达管道设备制造有限公司 |