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

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

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

      1. <tfoot id='cujO4'></tfoot>

        try-catch 不适用于 XMLHTTPRequest

        时间:2023-10-13

            <tfoot id='m5L4j'></tfoot>
          • <small id='m5L4j'></small><noframes id='m5L4j'>

              <tbody id='m5L4j'></tbody>
                <legend id='m5L4j'><style id='m5L4j'><dir id='m5L4j'><q id='m5L4j'></q></dir></style></legend>
                <i id='m5L4j'><tr id='m5L4j'><dt id='m5L4j'><q id='m5L4j'><span id='m5L4j'><b id='m5L4j'><form id='m5L4j'><ins id='m5L4j'></ins><ul id='m5L4j'></ul><sub id='m5L4j'></sub></form><legend id='m5L4j'></legend><bdo id='m5L4j'><pre id='m5L4j'><center id='m5L4j'></center></pre></bdo></b><th id='m5L4j'></th></span></q></dt></tr></i><div id='m5L4j'><tfoot id='m5L4j'></tfoot><dl id='m5L4j'><fieldset id='m5L4j'></fieldset></dl></div>
                  <bdo id='m5L4j'></bdo><ul id='m5L4j'></ul>
                  本文介绍了try-catch 不适用于 XMLHTTPRequest的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我正在尝试使用 try-catch 语句来处理来自 XMLHTTPRequest 的错误,如下所示:

                  I am trying to use the try-catch statements to handle the errors from XMLHTTPRequest, like below:

                  var xhr = new XMLHttpRequest();
                  xhr.open('POST', someurl, true);
                  try{
                      xhr.sendMultipart(object);
                  }
                  catch(err){
                      error_handle_function();
                  }
                  

                  xhr.sendMultipart 抛出 401 错误时,error_handle_function 未被调用.知道如何解决这个问题吗?

                  When there was a 401 error thrown by xhr.sendMultipart, the error_handle_function was not called. Any idea how to fix this?

                  谢谢!

                  推荐答案

                  我认为您无法以这种方式捕获服务器错误.你应该检查状态码:

                  I think you can't catch server errors that way. you should be checking the status code instead:

                  var xhr = new XMLHttpRequest();
                  xhr.onreadystatechange=function() {
                      if (xhr.readyState === 4){   //if complete
                          if(xhr.status === 200){  //check if "OK" (200)
                              //success
                          } else {
                              error_handle_function(); //otherwise, some other code was returned
                          }
                      } 
                  }
                  xhr.open('POST', someurl, true);
                  xhr.sendMultipart(object);
                  

                  这篇关于try-catch 不适用于 XMLHTTPRequest的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:jQuery $.ajax 或 $.load 是否允许 responseType arrayBuffe 下一篇:向所有 jQuery AJAX 请求添加自定义 http 标头

                  相关文章

                  最新文章

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

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

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

                      <tfoot id='D4oUB'></tfoot>