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

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

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

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

        使用 XMLHttpRequest 不断收到 No 'Access-Control-All

        时间:2023-10-14
        • <legend id='6aRl4'><style id='6aRl4'><dir id='6aRl4'><q id='6aRl4'></q></dir></style></legend>
          • <bdo id='6aRl4'></bdo><ul id='6aRl4'></ul>
              <tbody id='6aRl4'></tbody>

            1. <tfoot id='6aRl4'></tfoot>

                <small id='6aRl4'></small><noframes id='6aRl4'>

                • <i id='6aRl4'><tr id='6aRl4'><dt id='6aRl4'><q id='6aRl4'><span id='6aRl4'><b id='6aRl4'><form id='6aRl4'><ins id='6aRl4'></ins><ul id='6aRl4'></ul><sub id='6aRl4'></sub></form><legend id='6aRl4'></legend><bdo id='6aRl4'><pre id='6aRl4'><center id='6aRl4'></center></pre></bdo></b><th id='6aRl4'></th></span></q></dt></tr></i><div id='6aRl4'><tfoot id='6aRl4'></tfoot><dl id='6aRl4'><fieldset id='6aRl4'></fieldset></dl></div>
                • 本文介绍了使用 XMLHttpRequest 不断收到 No 'Access-Control-Allow-Origin' 错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我会通过使用 jQuery $.ajax 函数来解决这个问题,但在这种情况下,jQuery 不是选项.相反,我将使用 CORS 请求.我觉得响应请求的网络服务器有问题,我很难找出问题所在.

                  I would have solved this issue by using jQuery $.ajax function but in this case jQuery is not option. Instead I am going with CORS request. I feel there is something wrong with the webserver that is responding to the request and I am having a hard time figuring out what the issue is.

                  这是我创建 CORS 请求的代码

                  Here is my code for creating the CORS request

                  var httpRequest = new XMLHttpRequest();
                  httpRequest.open('POST', url, true);
                  httpRequest.setRequestHeader( 'Access-Control-Allow-Origin', '*');
                  httpRequest.setRequestHeader( 'Content-Type', 'application/json' );
                  httpRequest.onerror = function(XMLHttpRequest, textStatus, errorThrown) {
                    console.log( 'The data failed to load :(' );
                    console.log(JSON.stringify(XMLHttpRequest));
                  };
                  httpRequest.onload = function() {
                    console.log('SUCCESS!');
                  }
                  

                  这是 console.log 错误:

                  Here is the console.log error:

                  XMLHttpRequest 无法加载http://test.testhost.com/testpage.请求头域Access-Control-Allow-Origin 不允许访问控制允许标头.

                  XMLHttpRequest cannot load http://test.testhost.com/testpage. Request header field Access-Control-Allow-Origin is not allowed by Access-Control-Allow-Headers.

                  这是标题信息:

                  > Remote Address:**.**.***.**:80 Request
                  > URL:http://test.testdomain.com/testpage Request
                  > Request Method:OPTIONS
                  > Status Code:200 OK
                  

                  请求标头:

                  OPTIONS /content-network HTTP/1.1
                  Host: test.testhost.com
                  Connection: keep-alive
                  Cache-Control: no-cache
                  Pragma: no-cache
                  Access-Control-Request-Method: POST
                  Origin: http://test.testdomain.com
                  User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.125 Safari/537.36
                  Access-Control-Request-Headers: access-control-allow-origin, content-type
                  Accept: */*
                  Referer: http://test.testdomain.com/
                  Accept-Encoding: gzip,deflate,sdch
                  Accept-Language: en-US,en;q=0.8
                  

                  响应标头:

                  HTTP/1.1 200 OK
                  Date: Thu, 14 Aug 2014 20:17:25 GMT
                  Server: Apache
                  Last-Modified: Thu, 14 Aug 2014 20:17:25 +0000
                  Cache-Control: no-cache, must-revalidate, post-check=0, pre-check=0
                  ETag: "1408047445"
                  Access-Control-Allow-Origin: *
                  Access-Control-Allow-Headers: Content-Type
                  Vary: Accept-Encoding
                  Content-Encoding: gzip
                  Access-Control-Allow-Headers: origin, x-requested-with, content-type
                  Access-Control-Allow-Methods: PUT, GET, POST, DELETE, OPTIONS
                  Content-Length: 6117
                  Connection: close
                  Content-Type: text/html; charset=utf-8
                  

                  推荐答案

                  您的服务器的响应允许请求包含三个特定的 非简单标题:

                  Your server's response allows the request to include three specific non-simple headers:

                  Access-Control-Allow-Headers:origin, x-requested-with, content-type
                  

                  但是您的请求包含服务器响应不允许的标头:

                  but your request has a header not allowed by the server's response:

                  Access-Control-Request-Headers:access-control-allow-origin, content-type
                  

                  在 CORS 请求中发送的所有非简单标头必须由 Access-Control-Allow-Headers 响应标头明确允许.服务器的 CORS 响应不允许在您的请求中发送不必要的 Access-Control-Allow-Origin 标头.这正是...Access-Control-Allow-Headers 不允许"错误消息试图告诉您的内容.

                  All non-simple headers sent in a CORS request must be explicitly allowed by the Access-Control-Allow-Headers response header. The unnecessary Access-Control-Allow-Origin header sent in your request is not allowed by the server's CORS response. This is exactly what the "...not allowed by Access-Control-Allow-Headers" error message was trying to tell you.

                  请求没有理由有这个标头:它什么都不做,因为 Access-Control-Allow-Origin 是一个 response 标头,而不是请求标头.

                  There is no reason for the request to have this header: it does nothing, because Access-Control-Allow-Origin is a response header, not a request header.

                  解决方案:删除向您的请求添加 Access-Control-Allow-Origin 标头的 setRequestHeader 调用.

                  Solution: Remove the setRequestHeader call that adds a Access-Control-Allow-Origin header to your request.

                  这篇关于使用 XMLHttpRequest 不断收到 No 'Access-Control-Allow-Origin' 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:xmlhttprequest 和 set-cookie &amp;曲奇饼 下一篇:Safari 10.1:由于访问控制检查,无法加载带有查询

                  相关文章

                  最新文章

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

                      <small id='5s7c0'></small><noframes id='5s7c0'>

                      <tfoot id='5s7c0'></tfoot>