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

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

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

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

      1. jQuery Dropzone 的 CORS 問題并上傳到 Imgur

        CORS issues with jQuery Dropzone and upload to Imgur(jQuery Dropzone 的 CORS 問題并上傳到 Imgur)

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

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

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

              <tfoot id='Dzk2q'></tfoot>
                    <tbody id='Dzk2q'></tbody>
                • 本文介紹了jQuery Dropzone 的 CORS 問題并上傳到 Imgur的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我嘗試使用 jQuery Dropzone 將圖像上傳到 Imgur 或任何其他域,但這不起作用.

                  I tried to use jQuery Dropzone to upload an image to Imgur or any other domain but that's not working.

                  這是我的放置區設置:

                  $("div.dropzone").dropzone
                    success: -> console.log arguments
                    paramName: "image"
                    method: "post"
                    maxFilesize: 2
                    url: "https://api.imgur.com/3/upload"
                    headers:
                      Authorization: "Client-ID *************"
                  

                  這不起作用.它說返回碼是0.請求標頭:

                  This doesn't work. It says that return code is 0. The request headers:

                  Host: api.imgur.com
                  User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:31.0) Gecko/20100101 Firefox/31.0
                  Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
                  Accept-Language: fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3
                  Accept-Encoding: gzip, deflate
                  Origin: http://my.opencubes.io
                  Access-Control-Request-Method: POST
                  Access-Control-Request-Headers: authorization,cache-control,x-requested-with
                  Connection: keep-alive
                  Pragma: no-cache
                  Cache-Control: no-cache
                  

                  首先你可以看到cient id沒有出現:(.但最大的問題是使用的方法是OPTIONS.響應頭:

                  First as you can see the cient id doesn't appear :(. But the big problem is that the method used is OPTIONS. The response headers:

                  當我嘗試將文件上傳到我的另一個域時遇到同樣的問題(dropzone 位于子域中)

                  在我看到的控制臺中:

                  Une demande multi-origines (Cross-Origin Request) a été bloquée : la politique ? Same Origin ? ne permet pas de consulter la ressource distante située sur https://api.imgur.com/3/upload. Ceci peut être corrigé en dépla?ant la ressource sur le même domaine ou en activant CORS.
                  

                  可以翻譯的

                  多源請求被阻止:同源"策略不允許查看位于 https://api.imgur.com/3/upload.這可以通過移動 samin 域上的資源或啟用 CORS 來解決.

                  A multi-origin request was blocked: the policy "Same origin" does not allow to see remote resource located in https://api.imgur.com/3/upload. this an be fixed by moving the resource on the samin domain or by enabling CORS.

                  推薦答案

                  OPTIONS 請求是一個普通請求:用于請求與 CORS 限制相關的權限.查看此頁面了解如何CORS 在后臺工作.

                  The OPTIONS request is a normal request: this is used to ask for permissions relative to CORS restrictions. Have a look to this page to understand how CORS work under the hood.

                  在您的情況下,這是一個純粹的 CORS 相關問題.OPTIONS 請求包含此標頭:

                  In your case, this is a pure CORS related issue. The OPTIONS request contains this header:

                  Access-Control-Request-Headers: authorization,cache-control,x-requested-with
                  

                  這意味著:我可以在我的跨域AJAX請求?

                  Which means: can I use "authorization", "cache-control" and "x-requested-with" headers in my cross-domain AJAX request ?

                  您得到的響應如下:

                  Access-Control-Allow-Headers :"Authorization, Content-Type, Accept, X-Mashape-Authorization"
                  

                  這意味著:您只能使用這些標頭:Authorization"、Content-Type"、Accept"和X-Mashape-Authorization".

                  Which means: you're allowed to use those headers only: "Authorization", "Content-Type", "Accept", and "X-Mashape-Authorization".

                  如您所見,cache-control"和x-requested-with"未列出在允許列表中,導致瀏覽器拒絕請求.

                  As you can see, "cache-control" and "x-requested-with" are not listed in the allowed list, causing the browser to reject the request.

                  我來到了 2 個顯示這種行為的測試代碼示例:

                  I've come to 2 test code sample which show this behavior:

                  var data = new FormData();
                  data.append('image', 'http://placehold.it/300x500');
                  
                  var xhr = new XMLHttpRequest();
                  xhr.open('POST', 'https://api.imgur.com/3/upload', true);
                  xhr.setRequestHeader('Authorization', 'Client-ID xxxxxxxxxx');
                  xhr.send(data);
                  

                  以下是運行此代碼時發送的預檢請求標頭(如 Firefox 30 devtools 所示,我已刪除不相關的標頭,例如 User-Agent、Accept ...):

                  Here are the preflight request's headers sent when running this code (as shown by Firefox 30 devtools, and I've removed unrelated headers such as User-Agent, Accept ...):

                  • 選項 https://api.imgur.com/3/upload李>
                  • 主機:api.imgur.com
                  • 來源:http://local.host:8080
                  • 訪問控制請求方法:POST
                  • Access-Control-Request-Headers:授權
                  • 緩存控制:無緩存

                  以及對應的響應頭

                  • 訪問控制允許來源:*"
                  • Access-Control-Allow-Methods :"GET, PUT, POST, DELETE, OPTIONS"
                  • Access-Control-Allow-Headers :"授權、Content-Type、Accept、X-Mashape-Authorization"
                  • access-control-allow-origin :"*"
                  • Access-Control-Allow-Methods :"GET, PUT, POST, DELETE, OPTIONS"
                  • Access-Control-Allow-Headers :"Authorization, Content-Type, Accept, X-Mashape-Authorization"

                  在這里,我們可以看到我們提示訪問授權"頭,并且服務器正在接受這個頭,以及POST方法和任何原始URL,因此滿足CORS要求并且請求被允許瀏覽器.

                  Here, we can see that we prompt access to the "authorization" header, and the server is accepting this header, allong with the POST method and any origin URL, so the CORS requirements are satisfied and the request is allowed by the browser.

                  var data = new FormData();
                  data.append('image', 'http://placehold.it/300x500');
                  
                  var xhr = new XMLHttpRequest();
                  xhr.open('POST', 'https://api.imgur.com/3/upload', true);
                  xhr.setRequestHeader('Authorization', 'Client-ID xxxxxxxxxx');
                  // the only difference with the previous code is this line
                  xhr.setRequestHeader('Cache-Control', 'no-cache');
                  xhr.send(data);
                  

                  預檢請求的標頭:

                  • 選項https://api.imgur.com/3/upload
                  • 主機:api.imgur.com
                  • 來源:http://local.host:8080
                  • 訪問控制請求方法:POST
                  • Access-Control-Request-Headers:授權、緩存控制
                  • 緩存控制:無緩存

                  預檢響應的標頭(與示例 1 相同):

                  Preflight response's headers (which is the same as in example 1):

                  • 訪問控制允許來源:*"
                  • 訪問控制允許方法:GET、PUT、POST、DELETE、OPTIONS"
                  • Access-Control-Allow-Headers :"Authorization, Content-Type, Accept, X-Mashape-Authorization"

                  這里的Access-Control-Request-Headers"頭提示訪問cache-control",服務器不提供,所以CORS要求不滿足,請求是被瀏覽器拒絕.

                  Here, the "Access-Control-Request-Headers" header prompt access for "cache-control", which the server does not provide, so the CORS requirements are not satisfied and the request is rejected by the browser.

                  這里有一個 JSFiddle 引用不同的工作和不工作的演示來解決你的問題:http://jsfiddle.net/pomeh/Lfajnebh/.注意細節以了解發生了什么,評論很少,但他們在這里強調代碼中最棘手的部分.

                  Here's a JSFiddle referencing different working and not working demos for your problem: http://jsfiddle.net/pomeh/Lfajnebh/. Pay attention to details to understand what's going on, there is few comments but they are here to emphasis trickiest parts of the code.

                  作為獎勵,我已向 DropZone 的 GitHub 存儲庫發送了一個拉取請求以解決此問題(https://github.com/enyo/dropzone/pull/685),它允許您通過 DropZone 刪除預定義的標題.試試看:

                  As a bonus, I've sent a pull request to DropZone's GitHub repository to fix this problem (https://github.com/enyo/dropzone/pull/685) which allows you to remove pref-defined headers by DropZone. Give it a try:

                  var myDropzone = new Dropzone('.dropzone', {
                      //...
                      headers: {
                          'Authorization': authorizationHeader,
                          // remove Cache-Control and X-Requested-With
                          // to be sent along with the request
                          'Cache-Control': null,
                          'X-Requested-With': null
                      }
                  });
                  

                  上面的代碼應該適用于我的補丁版本(https://github.com/pomeh/dropzone/commit/f0063db6e5697888582421865840258dec1ffdc1),而上面的代碼不應該:

                  The code above should work with my patched version (https://github.com/pomeh/dropzone/commit/f0063db6e5697888582421865840258dec1ffdc1), whereas the code above should not:

                  var myDropzone = new Dropzone('.dropzone', {
                      //...
                      headers: {
                          'Authorization': authorizationHeader,
                          // remove Cache-Control and X-Requested-With
                          // to be sent along with the request
                      }
                  });
                  

                  這篇關于jQuery Dropzone 的 CORS 問題并上傳到 Imgur的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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))
                  XMLHttpRequest 206 Partial Content(XMLHttpRequest 206 部分內容)
                  Restrictions of XMLHttpRequest#39;s getResponseHeader()?(XMLHttpRequest 的 getResponseHeader() 的限制?)

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

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

                        <bdo id='jaK38'></bdo><ul id='jaK38'></ul>
                          <tbody id='jaK38'></tbody>
                        <legend id='jaK38'><style id='jaK38'><dir id='jaK38'><q id='jaK38'></q></dir></style></legend>

                            主站蜘蛛池模板: 膏方加工_丸剂贴牌_膏滋代加工_湖北康瑞生物科技有限公司 | 厦门ISO认证|厦门ISO9001认证|厦门ISO14001认证|厦门ISO45001认证-艾索咨询专注ISO认证行业 | 石家庄救护车出租_重症转院_跨省跨境医疗转送_活动赛事医疗保障_康复出院_放弃治疗_腾康26年医疗护送转诊团队 | 台湾HIWIN上银直线模组|导轨滑块|TBI滚珠丝杆丝杠-深圳汉工 | 杭州网络公司_百度SEO优化-外贸网络推广_抖音小程序开发-杭州乐软科技有限公司 | 膏方加工_丸剂贴牌_膏滋代加工_湖北康瑞生物科技有限公司 | ph计,实验室ph计,台式ph计,实验室酸度计,台式酸度计 | 衬塑设备,衬四氟设备,衬氟设备-淄博鲲鹏防腐设备有限公司 | 志高装潢官网-苏州老房旧房装修改造-二手房装修翻新 | 开平机_纵剪机厂家_开平机生产厂家|诚信互赢-泰安瑞烨精工机械制造有限公司 | 广州迈驰新GMP兽药包装机首页_药品包装机_中药散剂包装机 | 橡胶接头_橡胶软接头_套管伸缩器_管道伸缩器厂家-巩义市远大供水材料有限公司 | 广州印刷厂_广州彩印厂-广州艺彩印务有限公司 | 德国EA可编程直流电源_电子负载,中国台湾固纬直流电源_交流电源-苏州展文电子科技有限公司 | 飞飞影视_热门电影在线观看_影视大全 | 杭州厂房降温,车间降温设备,车间通风降温,厂房降温方案,杭州嘉友实业爽风品牌 | 数码管_LED贴片灯_LED数码管厂家-无锡市冠卓电子科技有限公司 | 带式过滤机厂家_价格_型号规格参数-江西核威环保科技有限公司 | 光照全温振荡器(智能型)-恒隆仪器| 翅片管散热器价格_钢制暖气片报价_钢制板式散热器厂家「河北冀春暖气片有限公司」 | 耐驰泵阀管件制造-耐驰泵阀科技(天津)有限公司 | 青岛代理记账_青岛李沧代理记账公司_青岛崂山代理记账一个月多少钱_青岛德辉财税事务所官网 | 上海办公室装修,办公楼装修设计,办公空间设计,企业展厅设计_写艺装饰公司 | 换网器_自动换网器_液压换网器--郑州海科熔体泵有限公司 | 招商帮-一站式网络营销服务|搜索营销推广|信息流推广|短视视频营销推广|互联网整合营销|网络推广代运营|招商帮企业招商好帮手 | 防勒索软件_数据防泄密_Trellix(原McAfee)核心代理商_Trellix(原Fireeye)售后-广州文智信息科技有限公司 | 懂研帝_专业SCI论文润色机构_SCI投稿发表服务公司 | 雨燕360体育免费直播_雨燕360免费NBA直播_NBA篮球高清直播无插件-雨燕360体育直播 | 银川美容培训-美睫美甲培训-彩妆纹绣培训-新娘化妆-学化妆-宁夏倍莱妮职业技能培训学校有限公司 临时厕所租赁_玻璃钢厕所租赁_蹲式|坐式厕所出租-北京慧海通 | 钢托盘,铁托盘,钢制托盘,镀锌托盘,饲料托盘,钢托盘制造商-南京飞天金属13260753852 | 热熔胶网膜|pes热熔网膜价格|eva热熔胶膜|热熔胶膜|tpu热熔胶膜厂家-苏州惠洋胶粘制品有限公司 | 低浓度恒温恒湿称量系统,强光光照培养箱-上海三腾仪器有限公司 | 安徽合肥格力空调专卖店_格力中央空调_格力空调总经销公司代理-皖格制冷设备 | 蒸压釜_蒸养釜_蒸压釜厂家-山东鑫泰鑫智能装备有限公司 | 雄松华章(广州华章MBA)官网-专注MBA/MPA/MPAcc/MEM辅导培训 | 存包柜厂家_电子存包柜_超市存包柜_超市电子存包柜_自动存包柜-洛阳中星 | 轻型地埋电缆故障测试仪,频响法绕组变形测试仪,静荷式卧式拉力试验机-扬州苏电 | 合肥触摸一体机_触摸查询机厂家_合肥拼接屏-安徽迅博智能科技 | 专业生物有机肥造粒机,粉状有机肥生产线,槽式翻堆机厂家-郑州华之强重工科技有限公司 | 新型游乐设备,360大摆锤游乐设备「诚信厂家」-山东方鑫游乐设备 新能源汽车电池软连接,铜铝复合膜柔性连接,电力母排-容发智能科技(无锡)有限公司 | 砍排机-锯骨机-冻肉切丁机-熟肉切片机-预制菜生产线一站式服务厂商 - 广州市祥九瑞盈机械设备有限公司 |