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

    <small id='1SmVt'></small><noframes id='1SmVt'>

        • <bdo id='1SmVt'></bdo><ul id='1SmVt'></ul>

        <legend id='1SmVt'><style id='1SmVt'><dir id='1SmVt'><q id='1SmVt'></q></dir></style></legend>

        <tfoot id='1SmVt'></tfoot>
        <i id='1SmVt'><tr id='1SmVt'><dt id='1SmVt'><q id='1SmVt'><span id='1SmVt'><b id='1SmVt'><form id='1SmVt'><ins id='1SmVt'></ins><ul id='1SmVt'></ul><sub id='1SmVt'></sub></form><legend id='1SmVt'></legend><bdo id='1SmVt'><pre id='1SmVt'><center id='1SmVt'></center></pre></bdo></b><th id='1SmVt'></th></span></q></dt></tr></i><div class="vzppdhl" id='1SmVt'><tfoot id='1SmVt'></tfoot><dl id='1SmVt'><fieldset id='1SmVt'></fieldset></dl></div>
      1. jQuery AJAX 調用導致錯誤狀態 403

        jQuery AJAX call results in error status 403(jQuery AJAX 調用導致錯誤狀態 403)

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

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

              <tbody id='xtG9G'></tbody>

              <tfoot id='xtG9G'></tfoot>
                <bdo id='xtG9G'></bdo><ul id='xtG9G'></ul>
                • <legend id='xtG9G'><style id='xtG9G'><dir id='xtG9G'><q id='xtG9G'></q></dir></style></legend>
                • 本文介紹了jQuery AJAX 調用導致錯誤狀態 403的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我正在使用 jQuery AJAX 對 Web 服務進行查詢.我的查詢如下所示:

                  I'm making a query to a web service using jQuery AJAX. My query looks like this:

                  var serviceEndpoint = 'http://example.com/object/details?version=1.1';
                  $.ajax({
                    type: 'GET', 
                    url: serviceEndpoint,
                    dataType: 'jsonp',
                    contentType: 'jsonp',
                    headers: { 'api-key':'myKey' },
                    success: onSuccess,
                    error: onFailure
                  });
                  

                  執行此操作時,我收到 403 狀態錯誤.我不明白為什么我的調用會導致狀態碼為 403.我控制著我的服務的安全性,它被標記為完全開放.我知道密鑰是有效的,因為我在另一個調用中使用它,它有效.這是有效的調用:

                  When I execute this, I get a status error of 403. I do not understand why my call results in having the status code 403. I'm in control of the security on my service and it is marked as wide-open. I know the key is valid, because I'm using it in another call, which works. Here is the call that works:

                  var endpoint = 'http://example.com/object/data/item?version=1.1';
                  $.ajax({ 
                    type: 'POST', 
                    url: endpoint, 
                    cache: 'false',
                    contentType:'application/json',
                    headers: {
                      'api-key':'myKey',
                      'Content-Type':'application/json'
                    },
                    data: JSON.stringify({
                      id: 5,
                      count:true
                    }),
                    success: onDataSuccess,
                    error: onDataFailure
                  });
                  

                  我知道這是兩個不同的端點.但我 100% 確信這不是服務器端身份驗證或權限錯誤.再一次,服務器端的一切都是開放的.這意味著我在客戶端請求上犯了一些錯誤.

                  I know these are two different endpoints. But I'm 100% convinced this is not a server-side authentication or permission error. Once again, everything is wide open on the server-side. Which implies that I'm making some mistake on my client-side request.

                  我覺得我應該傳達這個請求是在開發過程中提出的.所以,我從 http://localhost:3000 運行它.出于這個原因,我立即認為這是一個 CORS 問題.但一切看起來都是正確的.我的 POST 請求有效,但我的 GET 并沒有讓我感到非常沮喪.我錯過了什么嗎?會是什么?

                  I feel I should communicate that this request is being made during development. So, I'm running this from http://localhost:3000. For that reason, I immediately assumed it was a CORS issue. But everything looks correct. The fact that my POST request works, but my GET doesn't has me absolutely frustrated. Am I missing something? What could it be?

                  推薦答案

                  403錯誤的原因是你沒有發送headers.由于您正在發出 CORS 請求,因此您無法發送任何自定義標頭,除非服務器通過在響應中添加 Access-Control-Allow-Headers 來啟用這些標頭.

                  The reason of 403 error is you are not sending headers. Since you are making a CORS request, you cannot send any custom headers unless server enables these header by adding Access-Control-Allow-Headers to the response.

                  在 preflighted-request 中,客戶端向服務器發出 2 個請求.第一個是預檢(使用 OPTIONS 方法),第二個是真正的請求.服務器發送 Access-Control-Allow-Headers 標頭作為預檢請求的響應.因此,它可以發送一些標頭.通過這種方式,您的 POST 請求可以工作,因為 POST 請求是預檢請求.但是對于 GET 請求,沒有預檢來收集 Access-Control-Allow-Headers 標頭和瀏覽器在這種情況下不會發送您的自定義標頭.

                  In a preflighted-request, client makes 2 requests to the server. First one is preflight (with OPTIONS method) and the second one is the real request. The server sends Access-Control-Allow-Headers header as a response of the preflight request. So it enables some headers to be sent. By this way your POST request can work because the POST request is a preflight-request. But for a GET request, there is no preflight to gather Access-Control-Allow-Headers header and browser doesn't send your custom headers in this case.

                  解決此問題的方法:

                  作為一種解決方法,將您的 dataTypecontentType 設置為 json,如下所示:

                  As a workaround, set your dataType and contentType to json as the following:

                  var serviceEndpoint = 'http://example.com/object/details?version=1.1';
                  $.ajax({
                    type: 'GET', 
                    url: serviceEndpoint,
                    dataType: 'json',
                    contentType: 'json',
                    headers: { 'api-key':'myKey' },
                    success: onSuccess,
                    error: onFailure
                  });
                  

                  通過這種方式,您的獲取請求將是一個預檢請求.如果您的服務器使用 api-key" rel="nofollow noreferrer">Access-Control-Allow-Headers 標頭,它會起作用.

                  By this way, your get request will be a preflighted request. If your server enables the api-key with Access-Control-Allow-Headers header, it will work.

                  上述請求的示例服務器配置(用 express.js 編寫):

                  Sample server configuration for the above request (written in express.js):

                  res.setHeader('Access-Control-Allow-Origin', '*');
                  res.setHeader('Access-Control-Allow-Methods', '*');
                  res.setHeader('Access-Control-Allow-Headers', 'api-key,content-type');
                  res.setHeader('Access-Control-Allow-Credentials', true);
                  

                  添加:

                  實際上,contentType 應該是 application/javascriptapplication/json 在進行 jsonp 請求時.沒有 contentType 作為 jsonp.

                  Actually, contentType should be either application/javascript or application/json while doing a jsonp request. There is no contentType as jsonp.

                  這篇關于jQuery AJAX 調用導致錯誤狀態 403的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

                  相關文檔推薦

                  Browser waits for ajax call to complete even after abort has been called (jQuery)(即使在調用 abort (jQuery) 之后,瀏覽器也會等待 ajax 調用完成)
                  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 部分內容)
                  XmlHttpRequest onprogress interval(XmlHttpRequest onprogress 間隔)
                  <tfoot id='x61iy'></tfoot>
                    <i id='x61iy'><tr id='x61iy'><dt id='x61iy'><q id='x61iy'><span id='x61iy'><b id='x61iy'><form id='x61iy'><ins id='x61iy'></ins><ul id='x61iy'></ul><sub id='x61iy'></sub></form><legend id='x61iy'></legend><bdo id='x61iy'><pre id='x61iy'><center id='x61iy'></center></pre></bdo></b><th id='x61iy'></th></span></q></dt></tr></i><div class="fzfz5tl" id='x61iy'><tfoot id='x61iy'></tfoot><dl id='x61iy'><fieldset id='x61iy'></fieldset></dl></div>

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

                          <tbody id='x61iy'></tbody>

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

                            主站蜘蛛池模板: 交通气象站_能见度检测仪_路面状况监测站- 天合环境科技 | 量子管通环-自清洗过滤器-全自动反冲洗过滤器-北京罗伦过滤技术集团有限公司 | 定硫仪,量热仪,工业分析仪,马弗炉,煤炭化验设备厂家,煤质化验仪器,焦炭化验设备鹤壁大德煤质工业分析仪,氟氯测定仪 | 烟台金蝶财务软件,烟台网站建设,烟台网络推广 | 99文库_实习生实用的范文资料文库站 | 氧化锆纤维_1800度高温退火炉_1800度高温烧结炉-南京理工宇龙新材料股份有限公司 | 武汉不干胶印刷_标签设计印刷_不干胶标签印刷厂 - 武汉不干胶标签印刷厂家 | 国际船舶网 - 船厂、船舶、造船、船舶设备、航运及海洋工程等相关行业综合信息平台 | 亿立分板机_曲线_锯片式_走刀_在线式全自动_铣刀_在线V槽分板机-杭州亿协智能装备有限公司 | 打包箱房_集成房屋-山东佳一集成房屋有限公司 | 渗透仪-直剪仪-三轴仪|苏州昱创百科 | 移动机器人产业联盟官网| 热处理炉-退火炉-回火炉设备厂家-丹阳市电炉厂有限公司 | 北京自然绿环境科技发展有限公司专业生产【洗车机_加油站洗车机-全自动洗车机】 | 酒万铺-酒水招商-酒水代理 | 艺术漆十大品牌_艺术涂料加盟代理_蒙太奇艺术涂料厂家品牌|艺术漆|微水泥|硅藻泥|乳胶漆 | 海鲜池-专注海鲜鱼缸、移动海鲜缸、饭店鱼缸设计定做-日晟水族厂家 | 拉曼光谱仪_便携式|激光|显微共焦拉曼光谱仪-北京卓立汉光仪器有限公司 | 铁艺,仿竹,竹节,护栏,围栏,篱笆,栅栏,栏杆,护栏网,网围栏,厂家 - 河北稳重金属丝网制品有限公司 山东太阳能路灯厂家-庭院灯生产厂家-济南晟启灯饰有限公司 | 北京京云律师事务所 | 定时排水阀/排气阀-仪表三通旋塞阀-直角式脉冲电磁阀-永嘉良科阀门有限公司 | 海外仓系统|国际货代系统|退货换标系统|WMS仓储系统|海豚云 | 滑板场地施工_极限运动场地设计_滑板公园建造_盐城天人极限运动场地建设有限公司 | 轴流风机-鼓风机-离心风机-散热风扇-罩极电机,生产厂家-首肯电子 | 洛阳装修公司-洛阳整装一站式品牌-福尚云宅装饰 | 闸阀_截止阀_止回阀「生产厂家」-上海卡比阀门有限公司 | 泰安办公家具-泰安派格办公用品有限公司 | 铝机箱_铝外壳加工_铝外壳厂家_CNC散热器加工-惠州市铂源五金制品有限公司 | 大鼠骨髓内皮祖细胞-小鼠神经元-无锡欣润生物科技有限公司 | 污水处理设备维修_污水处理工程改造_机械格栅_过滤设备_气浮设备_刮吸泥机_污泥浓缩罐_污水处理设备_污水处理工程-北京龙泉新禹科技有限公司 | Copeland/谷轮压缩机,谷轮半封闭压缩机,谷轮涡旋压缩机,型号规格,技术参数,尺寸图片,价格经销商 CTP磁天平|小电容测量仪|阴阳极极化_双液系沸点测定仪|dsj电渗实验装置-南京桑力电子设备厂 | 禹城彩钢厂_钢结构板房_彩钢复合板-禹城泰瑞彩钢复合板加工厂 | 多功能干燥机,过滤洗涤干燥三合一设备-无锡市张华医药设备有限公司 | Akribis直线电机_直线模组_力矩电机_直线电机平台|雅科贝思Akribis-杭州摩森机电科技有限公司 | 无机纤维喷涂棉-喷涂棉施工工程-山东华泉建筑工程有限公司▲ | 模具硅橡胶,人体硅胶,移印硅胶浆厂家-宏图硅胶科技 | 成都装修公司-成都装修设计公司推荐-成都朗煜装饰公司 | 耐压仪-高压耐压仪|徐吉电气| 北京网站建设公司_北京网站制作公司_北京网站设计公司-北京爱品特网站建站公司 | 同学聚会纪念册制作_毕业相册制作-成都顺时针宣传画册设计公司 | 自动部分收集器,进口无油隔膜真空泵,SPME固相微萃取头-上海楚定分析仪器有限公司 |