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

    • <bdo id='YkJB9'></bdo><ul id='YkJB9'></ul>

    1. <tfoot id='YkJB9'></tfoot>
        <legend id='YkJB9'><style id='YkJB9'><dir id='YkJB9'><q id='YkJB9'></q></dir></style></legend>

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

        AngularJS $http 从失败的 CORS 请求返回状态码 0

        时间:2023-10-13
      1. <legend id='S6TTy'><style id='S6TTy'><dir id='S6TTy'><q id='S6TTy'></q></dir></style></legend>

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

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

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

                  本文介绍了AngularJS $http 从失败的 CORS 请求返回状态码 0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  好的,我已经找遍了这个.基本上我们使用的是跨域请求的 $http 请求.我们的服务器允许域,当请求返回 200 时,一切正常.但是,无论何时我们的服务器返回一个错误,500、401 等等,Angular 都会认为这是一个 CORS 问题.

                  Okay, I've looked all over for this. Basically we're using $http request that ARE cross domain requests. Our server allows the domain and when a request returns 200, everything is OK. However, anytime our server returns an error, 500, 401, whatever, Angular thinks it's a CORS issue.

                  我使用 Fiddler 调试了响应以验证我的服务器正在返回 500,但 Angular 会阻塞它.

                  I debugged the response with Fiddler to verify my server IS returning a 500, yet Angular chokes on it.

                  这是请求:

                         var params = {
                              url: "fakehost/example",
                              method: 'GET',
                              headers: {
                                  "Authorization": "Basic encodedAuthExample"
                              }
                          };
                  
                         $http(params).then(
                              function (response) { // success 
                  
                              },
                              function (error) { // error 
                                   // error.status is always 0, never includes data error msg
                              });
                  

                  然后在控制台中,我会看到这个:

                  Then in the console, I will see this:

                  XMLHttpRequest 无法加载 fakehost/example.请求的资源上不存在Access-Control-Allow-Origin"标头.因此,Origin 'mylocalhost:5750' 不允许访问.

                  XMLHttpRequest cannot load fakehost/example. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'mylocalhost:5750' is therefore not allowed access.

                  然而,在提琴手中,真正的反应是:

                  Yet, in fiddler, the true response is:

                  HTTP/1.1 500 Internal Server Error
                  Cache-Control: no-cache
                  Pragma: no-cache
                  Content-Type: application/json; charset=utf-8
                  Expires: -1
                  Server: Microsoft-IIS/7.5
                  X-AspNet-Version: 4.0.30319
                  X-Powered-By: ASP.NET
                  Date: Tue, 26 Aug 2014 12:18:17 GMT
                  Content-Length: 5683
                  
                  {"errorId":null,"errorMessage":"Index was outside the bounds of the array.","errorDescription":"Stack trace here"}
                  

                  我正在使用 AngularJS v1.2.16

                  I'm on AngularJS v1.2.16

                  推荐答案

                  我想我找到了答案,看起来你必须在你的 asp.net 管道中注入正确的 CORS 标头,如上所述 这里.

                  I think I found an answer, looks like you will have to inject in your asp.net pipeline the correct CORS headers, as mentioned here.

                  这篇关于AngularJS $http 从失败的 CORS 请求返回状态码 0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:向所有 jQuery AJAX 请求添加自定义 http 标头 下一篇:通过 XHR 请求下载 PDF 文件

                  相关文章

                  最新文章

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

                    1. <small id='oWYJW'></small><noframes id='oWYJW'>

                      <tfoot id='oWYJW'></tfoot>

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