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

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

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

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

      使用跨域資源共享的跨域 POST 查詢沒有返回數據

      Cross domain POST query using Cross-Origin Resource Sharing getting no data back(使用跨域資源共享的跨域 POST 查詢沒有返回數據)

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

        <bdo id='MLkHG'></bdo><ul id='MLkHG'></ul>
          <tbody id='MLkHG'></tbody>

          <tfoot id='MLkHG'></tfoot>

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

              1. 本文介紹了使用跨域資源共享的跨域 POST 查詢沒有返回數據的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                問題描述

                我正在通過 POST 請求跨域發送數據,但響應不起作用,具體來說,jQuery 的成功處理程序永遠不會被調用.

                I'm sending data cross domain via a POST request but the response isn't working, specifically, jQuery's success handler never gets called.

                使用的東西:Django、Apache、jQuery.

                Stuff being used: Django, Apache, jQuery.

                所以,我設置了一個與此類似的請求:

                So, I set up a request rather similar to this:

                $.ajax({
                    url: "http://somesite.com/someplace",
                    type: "POST",
                    cache: false,
                    dataType: "json",
                    data: { ... },
                    success: function( msg ) {
                        alert(msg);
                    },
                });
                

                眾所周知,CORS 允許我回復 OPTIONS 適當地查詢說是的,你可以發帖給我".我正在做的.Firebug 確認我收到了我的 200 狀態代碼,并且返回類型實際上是 application/json.但是,Firebug 也確認上面的成功處理程序沒有被調用.

                As you well know, CORS allows me to respond to an OPTIONS query appropriately to say "Yes, you can POST to me". Which I'm doing. Firebug confirms I'm getting my 200 status code and that the return type is in fact application/json. However, Firebug also confirms that the success handler in the above is not being called.

                作為參考,我對 OPTIONS 的回復是:

                For reference, my response to OPTIONS is:

                elif request.method == "OPTIONS":
                    response = HttpResponse("")
                    response['Access-Control-Allow-Origin'] = "*"
                    response['Access-Control-Allow-Methods'] = "POST, GET, OPTIONS"
                    response['Access-Control-Allow-Headers'] = "X-Requested-With"
                    return response
                

                相比之下,如果我設置一個 complete: function()... 處理程序,它就可以工作.

                In contrast, if I set up a complete: function()... handler it works.

                所以,問題是:發生了什么(或沒有發生),為什么?我得到的數據很好,我只想能夠返回響應.

                So, question is: what's happening (or not) and why? I am getting data fine, I'd just like to be able to return the response.

                更新:這解決了我在某些瀏覽器上的問題,但由于我對此行為沒有完整的明確解釋,所以我將其保持打開狀態.

                好的,所以我閱讀了手冊以及我對它的理解,算法應用的大致是這樣的:

                Ok, so I read the manual and what I understand of it, the algorithm applied is roughly this:

                1. 用戶代理可以實現預檢調用.這是 OPTIONS 請求.這個想法是他們提出這個請求,這給他們一個關于所請求資源的答案,然后他們應該緩存這些資源.我沒有傳回 max-age 字段,所以我懷疑在返回成功并且允許 X 請求時,用戶代理的緩存中沒有任何內容允許我這樣做,所以應用默認規則(隔離請求).
                2. 當您發出實際請求時,我相信用戶代理應該檢查飛行前緩存的權限.如果沒有我的 max-age 字段,我相信它找不到這些權限.但是,在 POST 上使用相同的標頭進行響應似乎允許 Firefox 和 Google Chrome 查看響應.歌劇不能.IE 目前尚未經過測試.
                1. User agents may implement a preflight call. This is the OPTIONS request. The idea is that they make this request which gives them an answer with respect to the requested resource, which they are then supposed to cache. I'm not passing back a max-age field, so I suspect whilst success is being returned and the X-request allowed, there is nothing in the user agent's cache which permitted me to make it, so the default rules (isolate the request) are applied.
                2. When you make the actual request, I believe the user agent is supposed to inspect the pre-flight cache for permissions. Without my max-age field, I believe it isn't finding these permissions. However, responding with the same headers on POST appears to allow Firefox and Google Chrome to view the response. Opera can not. IE remains untested at the moment.

                我目前不明白,從手冊中也不清楚(至少對我而言)CORS 請求是否也應該在請求中使用這些標頭以及 OPTIONS 來回答.我將試驗 Max-Age 標頭并查看允許或不允許的內容.但是,我對這個問題仍然缺乏一定的權威理解,所以如果這里有人知道,我會全力以赴.

                I do not currently understand and it is not clear from the manual (to me at least) whether a CORS request should also answer with these headers in the request as well as the OPTIONS. I shall experiment with the Max-Age header and see what that allows or does not allow. However, I'm still short of some definite authoritative understanding on the issue so if there is someone on here who knows, I'm all ears.

                推薦答案

                好吧,所以我相信正確的做事方式是這樣的:

                Ok, so I believe the correct way to do things is this:

                if request.method == "POST":
                    response = HttpResponse(simplejson.dumps(data),mimetype='application/json')
                    response['Access-Control-Allow-Origin'] = "*"
                    return response
                elif request.method == "OPTIONS":
                    response = HttpResponse("")
                    response['Access-Control-Allow-Origin'] = "*"
                    response['Access-Control-Allow-Methods'] = "POST, OPTIONS"
                    response['Access-Control-Allow-Headers'] = "X-Requested-With"
                    response['Access-Control-Max-Age'] = "1800"
                else:
                    return HttpResponseBadRequest()
                

                這是基于我從 Mozilla 挖掘的關于預檢請求的文檔.

                This is based on the documentation I dug up from Mozilla on preflighted requests.

                所以,我相信會發生這樣的事情:

                So, what I believe will happen is this:

                1. 如果預檢緩存中沒有任何內容,則發送 OPTIONS 并將 X-Requested-With 設置為 XMLHttpRequest 我相信這是必要的允許 Javascript 訪問任何內容,以及 Origin 標頭.
                2. 服務器可以檢查該信息.這就是 CORS 的安全性.就我而言,我的回應是任何來源都可以"和你可以發送 X-Requested-With 東西".我是說 OPTIONSPOST 是允許的,并且這個響應應該被緩存 30 分鐘.
                3. 然后客戶端繼續進行 POST,這在之前是有效的.
                4. 我最初修改了響應以包含 Allow-MethodsAllow-Headers 但根據上述鏈接文檔中的交換,這不是必需的.這是有道理的,訪問檢查已經完成.
                5. 我相信會發生此處描述的資源共享檢查.基本上,一旦提出了上述請求,瀏覽器就會再次檢查 Allow-Origin 字段的有效性,這在諸如 POST 之類的請求上.如果通過,客戶端可以訪問數據,如果沒有,則請求已經完成,但瀏覽器拒絕實際的客戶端應用程序 (Javascript) 訪問該數據.
                1. If there's nothing in the preflight cache, OPTIONS is sent with X-Requested-With set to XMLHttpRequest I believe this is necessary to allow Javascript access to anything, along with an Origin header.
                2. The server can examine that information. That is the security of CORS. In my case, I'm responding with "any origin will do" and "you're allowed to send the X-Requested-With thing". I'm saying that OPTIONS and POST are allowed and that this response should be cached for 30 mins.
                3. The client then goes ahead and makes the POST, which was working before.
                4. I modified the response originally to include Allow-Methods and Allow-Headers but according to the exchange in the above linked documentation this isn't needed. This makes sense, the access check has already been done.
                5. I believe then that what happens is the resource sharing check described here. Basically, once said request has been made, the browser again checks the Allow-Origin field for validity, this being on the request such as POST. If this passes, the client can have access to the data, if not, the request has already completed but the browser denies the actual client side application (Javascript) access to that data.

                我相信這是對正在發生的事情的正確總結,并且無論如何它似乎有效.如果我說的不對,請大聲疾呼.

                I believe that is a correct summary of what is going on and in any case it appears to work. If I'm not right, please shout.

                這篇關于使用跨域資源共享的跨域 POST 查詢沒有返回數據的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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 部分內容)
                <i id='chmyr'><tr id='chmyr'><dt id='chmyr'><q id='chmyr'><span id='chmyr'><b id='chmyr'><form id='chmyr'><ins id='chmyr'></ins><ul id='chmyr'></ul><sub id='chmyr'></sub></form><legend id='chmyr'></legend><bdo id='chmyr'><pre id='chmyr'><center id='chmyr'></center></pre></bdo></b><th id='chmyr'></th></span></q></dt></tr></i><div class="yo2y0ki" id='chmyr'><tfoot id='chmyr'></tfoot><dl id='chmyr'><fieldset id='chmyr'></fieldset></dl></div>

                <legend id='chmyr'><style id='chmyr'><dir id='chmyr'><q id='chmyr'></q></dir></style></legend>

                      <tbody id='chmyr'></tbody>

                  • <tfoot id='chmyr'></tfoot>
                      <bdo id='chmyr'></bdo><ul id='chmyr'></ul>

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

                          主站蜘蛛池模板: 微动开关厂家-东莞市德沃电子科技有限公司 | 山东石英砂过滤器,除氟过滤器「价格低」-淄博胜达水处理 | 长沙印刷厂-包装印刷-画册印刷厂家-湖南省日大彩色印务有限公司 青州搬家公司电话_青州搬家公司哪家好「鸿喜」青州搬家 | 小型高低温循环试验箱-可程式高低温湿热交变试验箱-东莞市拓德环境测试设备有限公司 | 课件导航网_ppt课件_课件模板_课件下载_最新课件资源分享发布平台 | 东风体检车厂家_公共卫生体检车_医院体检车_移动体检车-锦沅科贸 | 东莞精密模具加工,精密连接器模具零件,自動機零件,冶工具加工-益久精密 | 水冷式工业冷水机组_风冷式工业冷水机_水冷螺杆冷冻机组-深圳市普威机械设备有限公司 | 烟台条码打印机_烟台条码扫描器_烟台碳带_烟台数据采集终端_烟台斑马打印机-金鹏电子-金鹏电子 | 座椅式升降机_无障碍升降平台_残疾人升降平台-南京明顺机械设备有限公司 | 细石混凝土泵_厂家_价格-烟台九达机械有限公司 | 福建成考网-福建成人高考网| 威实软件_软件定制开发_OA_OA办公系统_OA系统_办公自动化软件 | 通信天线厂家_室分八木天线_对数周期天线_天线加工厂_林创天线源头厂家 | 国际船舶网 - 船厂、船舶、造船、船舶设备、航运及海洋工程等相关行业综合信息平台 | 上海诺狮景观规划设计有限公司| 啤酒设备-小型啤酒设备-啤酒厂设备-济南中酿机械设备有限公司 | 精密交叉滚子轴承厂家,转盘轴承,YRT转台轴承-洛阳千协轴承 | SMC-SMC电磁阀-日本SMC气缸-SMC气动元件展示网 | 北京律师咨询_知名专业北京律师事务所_免费法律咨询 | 减速机三参数组合探头|TSM803|壁挂式氧化锆分析仪探头-安徽鹏宸电气有限公司 | 成都软件开发_OA|ERP|CRM|管理系统定制开发_成都码邻蜀科技 | 移动厕所租赁|移动卫生间|上海移动厕所租赁-家瑞租赁 | PU树脂_水性聚氨酯树脂_聚氨酯固化剂_聚氨酯树脂厂家_宝景化工 | 等离子表面处理机-等离子表面活化机-真空等离子清洗机-深圳市东信高科自动化设备有限公司 | 机器视觉检测系统-视觉检测系统-机器视觉系统-ccd检测系统-视觉控制器-视控一体机 -海克易邦 | 环讯传媒,永康网络公司,永康网站建设,永康小程序开发制作,永康网站制作,武义网页设计,金华地区网站SEO优化推广 - 永康市环讯电子商务有限公司 | 济南网站建设_济南网站制作_济南网站设计_济南网站建设公司_富库网络旗下模易宝_模板建站 | 昆山新莱洁净应用材料股份有限公司-卫生级蝶阀,无菌取样阀,不锈钢隔膜阀,换向阀,离心泵 | X光检测仪_食品金属异物检测机_X射线检测设备_微现检测 | 机制砂选粉机_砂石选粉机厂家-盐城市助成粉磨科技有限公司 | 干粉砂浆设备-干粉砂浆生产线-干混-石膏-保温砂浆设备生产线-腻子粉设备厂家-国恒机械 | LZ-373测厚仪-华瑞VOC气体检测仪-个人有毒气体检测仪-厂家-深圳市深博瑞仪器仪表有限公司 | Brotu | 关注AI,Web3.0,VR/AR,GPT,元宇宙区块链数字产业 | 户外健身路径_小区健身器材_室外健身器材厂家_价格-浩然体育 | 北京燃气公司 用户服务中心 | 高扬程排污泵_隔膜泵_磁力泵_节能自吸离心水泵厂家-【上海博洋】 | 锡膏喷印机-全自动涂覆机厂家-全自动点胶机-视觉点胶机-深圳市博明智控科技有限公司 | 经济师考试_2025中级经济师报名时间_报名入口_考试时间_华课网校经济师培训网站 | 知企服务-企业综合服务(ZiKeys.com)-品优低价、种类齐全、过程管理透明、速度快捷高效、放心服务,知企专家! | 铝机箱_铝外壳加工_铝外壳厂家_CNC散热器加工-惠州市铂源五金制品有限公司 |