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

<small id='98Ut8'></small><noframes id='98Ut8'>

      • <bdo id='98Ut8'></bdo><ul id='98Ut8'></ul>

    1. <legend id='98Ut8'><style id='98Ut8'><dir id='98Ut8'><q id='98Ut8'></q></dir></style></legend>
      <i id='98Ut8'><tr id='98Ut8'><dt id='98Ut8'><q id='98Ut8'><span id='98Ut8'><b id='98Ut8'><form id='98Ut8'><ins id='98Ut8'></ins><ul id='98Ut8'></ul><sub id='98Ut8'></sub></form><legend id='98Ut8'></legend><bdo id='98Ut8'><pre id='98Ut8'><center id='98Ut8'></center></pre></bdo></b><th id='98Ut8'></th></span></q></dt></tr></i><div class="esa6kkc" id='98Ut8'><tfoot id='98Ut8'></tfoot><dl id='98Ut8'><fieldset id='98Ut8'></fieldset></dl></div>
      <tfoot id='98Ut8'></tfoot>

        跨域 AJAX 請(qǐng)求不起作用

        Cross-domain AJAX request not working(跨域 AJAX 請(qǐng)求不起作用)

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

              <tbody id='qjWA2'></tbody>
              1. <legend id='qjWA2'><style id='qjWA2'><dir id='qjWA2'><q id='qjWA2'></q></dir></style></legend>
                • <bdo id='qjWA2'></bdo><ul id='qjWA2'></ul>

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

                  本文介紹了跨域 AJAX 請(qǐng)求不起作用的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                  問題描述

                  我正在通過 jQuery 的 $.ajax 函數(shù)在我一直使用的第三方 API 上調(diào)用 POST.但是,當(dāng)我撥打電話時(shí),我收到以下錯(cuò)誤:XMLHttpRequest 無法加載 http://the-url.com.該請(qǐng)求被重定向到http://the-url.com/anotherlocation",這對(duì)于需要預(yù)檢的跨域請(qǐng)求是不允許的.

                  I'm calling POST on a third-party API that I've been working with via jQuery's $.ajax function. However, when I make the call I get the following error: XMLHttpRequest cannot load http://the-url.com. The request was redirected to 'http://the-url.com/anotherlocation', which is disallowed for cross-origin requests that require preflight.

                  我從 這篇文章中看到 這可能是一個(gè) Webkit 錯(cuò)誤,所以我在 Firefox 中進(jìn)行了嘗試(我正在 Chrome 中開發(fā)),我得到了相同的結(jié)果.我在 Chrome 和 Firefox 上嘗試過,我得到了相同的結(jié)果.

                  I saw from this post that this might be a Webkit bug, so I tried it in Firefox (I'm developing in Chrome) and I got the same result.I've tried this on Chrome and Firefox and I get the same result.

                  根據(jù) 這篇文章,我還嘗試通過設(shè)置 crossDomain 來使用 jsonp$.ajax 函數(shù)的 屬性為 true 并將 dataType 設(shè)置為 jsonp.但是,這導(dǎo)致了 500 內(nèi)部服務(wù)器錯(cuò)誤.

                  Per this post, I also tried using jsonp both by setting the crossDomain property of the $.ajax function to true and setting the dataType to jsonp. But, this caused a 500 internal server error.

                  當(dāng)我使用 --disable-web-security 標(biāo)志啟動(dòng) Chrome 時(shí),我沒有任何問題.但是,如果我正常啟動(dòng)瀏覽器,則會(huì)收到錯(cuò)誤消息.

                  When I start Chrome with the --disable-web-security flag, I don't have any problems. However, if I start the browser normally, then I get the error.

                  所以,我想這可能是一個(gè)由兩部分組成的問題.我該怎么做才能發(fā)出這個(gè)跨域請(qǐng)求?如果 JSONP 是答案,那么我該如何確定第三方 API 是否設(shè)置正確以支持此功能?

                  So, I guess this might sort of be a 2-part question. What can I do to make this cross-domain request? If JSONP is the answer, then how do I go about figuring out if the third-party API is set up correctly to support this?

                  這是我在禁用瀏覽器安全性的情況下?lián)艽螂娫挄r(shí)的屏幕截圖:https://drive.google.com/file/d/0Bzo7loNBQcmjUjk5YWNWLXM2SVE/edit?usp=sharing

                  Here's the screenshot when I make the call with the browser security disabled: https://drive.google.com/file/d/0Bzo7loNBQcmjUjk5YWNWLXM2SVE/edit?usp=sharing

                  這是我在啟用瀏覽器安全性的情況下(正常情況下)撥打電話時(shí)的屏幕截圖:https://drive.google.com/file/d/0Bzo7loNBQcmjam5NQ3BKWUluRE0/edit?usp=sharing

                  Here's the screenchost when I make the call with the browser security enabled (like normal): https://drive.google.com/file/d/0Bzo7loNBQcmjam5NQ3BKWUluRE0/edit?usp=sharing

                  推薦答案

                  我想出的解決方案是使用 cURL(正如 @waki 所提到的),但稍微修改了一個(gè)支持 SOAP 的版本.然后,我沒有對(duì)第三方 API 進(jìn)行 AJAX 調(diào)用(配置不正確),而是調(diào)用我的本地 PHP 文件,該文件然后對(duì)第三方 API 進(jìn)行 SOAP 調(diào)用并將數(shù)據(jù)傳遞回我的 PHP 文件,我可以然后處理它.這讓我忘記了 CORS 以及與之相關(guān)的所有復(fù)雜性.這是代碼(取自this問題,但沒有經(jīng)過身份驗(yàn)證).

                  The solution that I came up with was to use cURL (as @waki mentioned), but a slightly modified version that supports SOAP. Then, instead of making the AJAX call to the third party API (which is configured incorrectly) I make the call to my local PHP file which then makes a SOAP call to third party API and passes the data back to my PHP file where I can then process it. This allows me to forget about CORS and all of the complexities associated with it. Here's the code (taken and modified from this question, but without the authentication).

                  $post_data = "Some xml here";
                  $soapUrl = "http://yoursite.com/soap.asmx"; // asmx URL of WSDL
                  
                  
                  $headers = array(
                      "Content-type: text/xml;charset="utf-8"",
                      "Accept: text/xml",
                      "Cache-Control: no-cache",
                      "Pragma: no-cache",
                      "SOAPAction: http://yoursite.com/SOAPAction",
                      "Content-length: " . strlen($post_data),
                  ); //SOAPAction: your op URL
                  
                  $url = $soapUrl;
                  
                  // PHP cURL
                  $ch = curl_init();
                  curl_setopt($ch, CURLOPT_URL, $url);
                  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
                  curl_setopt($ch, CURLOPT_POST, true);
                  curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); // the SOAP request
                  curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
                  
                  $response = curl_exec($ch);
                  
                  /* Check for an error when processing the request. */
                  if(curl_errno($ch) != 0) {
                     // TODO handle the error
                  }
                  
                  curl_close($ch);
                  
                  // TODO Parse and process the $response variable (returned as XML)
                  

                  這篇關(guān)于跨域 AJAX 請(qǐng)求不起作用的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                  【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(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)用完成)
                  XMLHttpRequest cannot load, No #39;Access-Control-Allow-Origin#39; header is present on the requested resource(XMLHttpRequest 無法加載,請(qǐng)求的資源上不存在“Access-Control-Allow-Origin標(biāo)頭) - IT屋-程序員軟件開發(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)容)
                  XmlHttpRequest onprogress interval(XmlHttpRequest onprogress 間隔)

                    • <small id='maX15'></small><noframes id='maX15'>

                      <legend id='maX15'><style id='maX15'><dir id='maX15'><q id='maX15'></q></dir></style></legend>
                        <bdo id='maX15'></bdo><ul id='maX15'></ul>
                        <i id='maX15'><tr id='maX15'><dt id='maX15'><q id='maX15'><span id='maX15'><b id='maX15'><form id='maX15'><ins id='maX15'></ins><ul id='maX15'></ul><sub id='maX15'></sub></form><legend id='maX15'></legend><bdo id='maX15'><pre id='maX15'><center id='maX15'></center></pre></bdo></b><th id='maX15'></th></span></q></dt></tr></i><div class="ewpxt8b" id='maX15'><tfoot id='maX15'></tfoot><dl id='maX15'><fieldset id='maX15'></fieldset></dl></div>
                          <tbody id='maX15'></tbody>
                          <tfoot id='maX15'></tfoot>
                          1. 主站蜘蛛池模板: 北京网站建设-企业网站建设-建站公司-做网站-北京良言多米网络公司 | 考勤系统_考勤管理系统_网络考勤软件_政企|集团|工厂复杂考勤工时统计排班管理系统_天时考勤 | 清水-铝合金-建筑模板厂家-木模板价格-铝模板生产「五棵松」品牌 | 电机铸铝配件_汽车压铸铝合金件_发动机压铸件_青岛颖圣赫机械有限公司 | 定时排水阀/排气阀-仪表三通旋塞阀-直角式脉冲电磁阀-永嘉良科阀门有限公司 | 收录网| 一体化隔油提升设备-餐饮油水分离器-餐厨垃圾处理设备-隔油池-盐城金球环保产业发展有限公司 | 气力输送设备_料封泵_仓泵_散装机_气化板_压力释放阀-河南锐驰机械设备有限公司 | 高低温老化试验机-步入式/低温恒温恒湿试验机-百科 | 电力电子产业网 | 仓储货架_南京货架_钢制托盘_仓储笼_隔离网_环球零件盒_诺力液压车_货架-南京一品仓储设备制造公司 | 开云(中国)Kaiyun·官方网站-登录入口 | 华夏医界网_民营医疗产业信息平台_民营医院营销管理培训 | 电子万能试验机_液压拉力试验机_冲击疲劳试验机_材料试验机厂家-济南众标仪器设备有限公司 | 广东护栏厂家-广州护栏网厂家-广东省安麦斯交通设施有限公司 | 卡诺亚轻高定官网_卧室系统_整家定制_定制家居_高端定制_全屋定制加盟_定制家具加盟_定制衣柜加盟 | 蜗轮丝杆升降机-螺旋升降机-丝杠升降机厂家-润驰传动 | STRO|DTRO-STRO反渗透膜(科普)_碟滤 | 玻璃钢罐_玻璃钢储罐_盐酸罐厂家-河北华盛节能设备有限公司 | 耳模扫描仪-定制耳机设计软件-DLP打印机-asiga打印机-fitshape「飞特西普」 | 广州工业氧气-工业氩气-工业氮气-二氧化碳-广州市番禺区得力气体经营部 | 节流截止放空阀-不锈钢阀门-气动|电动截止阀-鸿华阀门有限公司 | 盛源真空泵|空压机-浙江盛源空压机制造有限公司-【盛源官网】 | 5nd音乐网|最新流行歌曲|MP3歌曲免费下载|好听的歌|音乐下载 免费听mp3音乐 | 山东限矩型液力偶合器_液力耦合器易熔塞厂家-淄博市汇川源机械厂 | 铝合金线槽_铝型材加工_空调挡水板厂家-江阴炜福金属制品有限公司 | 冷藏车厂家|冷藏车价格|小型冷藏车|散装饲料车厂家|程力专用汽车股份有限公司销售十二分公司 | 浩方智通 - 防关联浏览器 - 跨境电商浏览器 - 云雀浏览器 | 井式炉-台车式回火炉-丹阳市电炉厂有限公司 | 济南画室培训-美术高考培训-山东艺霖艺术培训画室 | 水质传感器_水质监测站_雨量监测站_水文监测站-山东水境传感科技有限公司 | 注塑_注塑加工_注塑模具_塑胶模具_注塑加工厂家_深圳环科 | 3A别墅漆/3A环保漆_广东美涂士建材股份有限公司【官网】 | 液压扳手-高品质液压扳手供应商 - 液压扳手, 液压扳手供应商, 德国进口液压拉马 | 珠海白蚁防治_珠海灭鼠_珠海杀虫灭鼠_珠海灭蟑螂_珠海酒店消杀_珠海工厂杀虫灭鼠_立净虫控防治服务有限公司 | 盘式曝气器-微孔曝气器-管式曝气器-曝气盘-斜管填料 | 郑州市前程水处理有限公司 | 冷却塔厂家_冷却塔维修_冷却塔改造_凉水塔配件填料公司- 广东康明节能空调有限公司 | 儿童乐园|游乐场|淘气堡招商加盟|室内儿童游乐园配套设备|生产厂家|开心哈乐儿童乐园 | 北京网站建设公司_北京网站制作公司_北京网站设计公司-北京爱品特网站建站公司 | 膏方加工_丸剂贴牌_膏滋代加工_湖北康瑞生物科技有限公司 | 山东PE给水管厂家,山东双壁波纹管,山东钢带增强波纹管,山东PE穿线管,山东PE农田灌溉管,山东MPP电力保护套管-山东德诺塑业有限公司 |