• <bdo id='kaExo'></bdo><ul id='kaExo'></ul>
    1. <tfoot id='kaExo'></tfoot>
    2. <i id='kaExo'><tr id='kaExo'><dt id='kaExo'><q id='kaExo'><span id='kaExo'><b id='kaExo'><form id='kaExo'><ins id='kaExo'></ins><ul id='kaExo'></ul><sub id='kaExo'></sub></form><legend id='kaExo'></legend><bdo id='kaExo'><pre id='kaExo'><center id='kaExo'></center></pre></bdo></b><th id='kaExo'></th></span></q></dt></tr></i><div id='kaExo'><tfoot id='kaExo'></tfoot><dl id='kaExo'><fieldset id='kaExo'></fieldset></dl></div>
    3. <small id='kaExo'></small><noframes id='kaExo'>

    4. <legend id='kaExo'><style id='kaExo'><dir id='kaExo'><q id='kaExo'></q></dir></style></legend>

        指定标头时,jQuery AJAX 无法工作(OPTIONS 飞行前请求)

        jQuery AJAX fails to work (OPTIONS pre-flight request made) when headers are specified(指定标头时,jQuery AJAX 无法工作(OPTIONS 飞行前请求))
        <tfoot id='ujIfw'></tfoot>
          • <i id='ujIfw'><tr id='ujIfw'><dt id='ujIfw'><q id='ujIfw'><span id='ujIfw'><b id='ujIfw'><form id='ujIfw'><ins id='ujIfw'></ins><ul id='ujIfw'></ul><sub id='ujIfw'></sub></form><legend id='ujIfw'></legend><bdo id='ujIfw'><pre id='ujIfw'><center id='ujIfw'></center></pre></bdo></b><th id='ujIfw'></th></span></q></dt></tr></i><div id='ujIfw'><tfoot id='ujIfw'></tfoot><dl id='ujIfw'><fieldset id='ujIfw'></fieldset></dl></div>
          • <small id='ujIfw'></small><noframes id='ujIfw'>

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

                1. 本文介绍了指定标头时,jQuery AJAX 无法工作(OPTIONS 飞行前请求)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  AJAX 请求工作正常,但是当我通过 beforeSend 或 headers 添加标头时,会发出一个 OPTIONS 飞行前请求并中止 GET 请求.

                  The AJAX request works fine, but the moment I add a header via beforeSend or headers, an OPTIONS pre-flight request is made and the GET request is aborted.

                    Code: $.ajax({
                          type: "GET",
                          crossDomain: true,
                           beforeSend: function (xhr)
                           {
                           xhr.setRequestHeader("session", $auth);
                           },
                          url: $url,
                          success: function (data) {
                              $('#something').html(data);
                          },
                          error: function (request, error) {
                              $('#something').html("<p>Error getting values</p>");
                          }
                      });
                  

                  类似 AJAX 请求不指定标头(当我添加/修改标头时,会进行 OPTIONS 调用)

                  Similar AJAX Request w/o headers specified (the moment I add/modify header, an OPTIONS call is made)

                  Request GET /api/something?filter=1 HTTP/1.1
                  Referer http://app.xyz.dj/dashboard
                  Accept  application/json, text/javascript, */*; q=0.01
                  Accept-Language en-US
                  Origin  http://app.xyz.dj
                  Accept-Encoding gzip, deflate
                  User-Agent  Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; MASMJS; rv:11.0) like Gecko
                  Host    162.243.13.172:8080
                  DNT 1
                  Connection  Keep-Alive
                  Cache-Control   no-cache
                  

                  类似的服务器响应标头(用于 GET 请求)

                  Similar Server Response Header (for GET request)

                  Response    HTTP/1.1 200 OK
                  Server  Apache-Coyote/1.1
                  Access-Control-Allow-Origin *
                  Access-Control-Allow-Methods    GET, POST, DELETE, PUT, OPTIONS, HEAD
                  Access-Control-Allow-Headers    Content-Type, Accept, X-Requested-With
                  Access-Control-Allow-Credentials    true
                  Content-Type    application/json
                  Transfer-Encoding   chunked
                  Date    Thu, 09 Jan 2014 14:43:07 GMT
                  

                  我做错了什么?

                  推荐答案

                  解决了.感谢@JasonP 的指点.将服务器 响应标头 更改为

                  Solved. Thanks @JasonP for pointers. Changed Server Response Headers from

                  访问控制允许标头:*

                  到特定的

                  Access-Control-Allow-Headers:Content-Type、Accept、X-Requested-With、Session

                  Access-Control-Allow-Headers: Content-Type, Accept, X-Requested-With, Session

                  现在它可以工作了!

                  这篇关于指定标头时,jQuery AJAX 无法工作(OPTIONS 飞行前请求)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  How to set a header for a HTTP GET request, and trigger file download?(如何为 HTTP GET 请求设置标头并触发文件下载?)
                  Adding custom HTTP headers using JavaScript(使用 JavaScript 添加自定义 HTTP 标头)
                  What is quot;X-Content-Type-Options=nosniffquot;?(什么是“X-Content-Type-Options=nosniff?)
                  SmtpJs API not working! is there any way to send emails using SMTP server with JavaScript or JQuery(SmtpJs API 不工作!有没有办法使用带有 JavaScript 或 JQuery 的 SMTP 服务器发送电子邮件)
                  How can i create Canvas Image from image sources in an array?(如何从数组中的图像源创建画布图像?)
                  Sweet Alert Pop up Prompt Before Downloading Canvas HTML Image to PNG(在将 Canvas HTML 图像下载为 PNG 之前弹出甜蜜警报提示)
                2. <small id='N8loC'></small><noframes id='N8loC'>

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

                        <bdo id='N8loC'></bdo><ul id='N8loC'></ul>
                        <tfoot id='N8loC'></tfoot>

                              <tbody id='N8loC'></tbody>