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

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

      <legend id='BJ8ng'><style id='BJ8ng'><dir id='BJ8ng'><q id='BJ8ng'></q></dir></style></legend>
        <bdo id='BJ8ng'></bdo><ul id='BJ8ng'></ul>
      1. XMLHttpRequest 的 onerror 处理程序应该何时触发

        时间:2023-10-14
      2. <legend id='dW8Nv'><style id='dW8Nv'><dir id='dW8Nv'><q id='dW8Nv'></q></dir></style></legend>
        • <small id='dW8Nv'></small><noframes id='dW8Nv'>

            <bdo id='dW8Nv'></bdo><ul id='dW8Nv'></ul>
                  <tbody id='dW8Nv'></tbody>

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

                  本文介绍了XMLHttpRequest 的 onerror 处理程序应该何时触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我在理解 XMLHttpRequest 的处理程序时有点问题.规范说明了 onerror 处理程序:

                  I have a little problem understanding XMLHttpRequest's handlers. The specification says this about the onerror handler:

                  error [Dispatched ... ] 请求失败时.

                  error [Dispatched ... ] When the request has failed.

                  load [Dispatched ... ] 当请求成功完成时.

                  load [Dispatched ... ] When the request has successfully completed.

                  问题是,请求失败"是什么意思.那可能是

                  The problem is, what does it mean that "the request has failed". That could be

                  • 根本无法发出请求(例如,连接被拒绝和此类错误),或者
                  • 上面加上服务器返回了一个错误代码(例如404)

                  另外,我想知道这是否意味着 onerroronload 不应该同时触发.

                  Also, I'd like to know whether it means onerror and onload should never fire simultaneously.

                  此引用 表示应该执行 onerror 处理程序取决于 status 代码和 onload 取决于 readyState.这表明它们并不相互排斥,但是,我认为这不是权威信息.

                  This reference indicates the onerror handler should be executed depending on the status code and onload depending on readyState. That would indicate they are not mutually exclusive, however, I don't think this is an authoritative information.

                  我问是因为使用最新的 Opera 快照,我发现即使在 404 状态码上也会触发 onload.我知道测试 status 是肯定的,但我想知道这是我必须按照规范执行的操作,还是只是解决 Opera 中的错误的一种解决方法.

                  I'm asking because using the latest Opera snapshot, I found onload is fired even on 404 status code. I know testing status is a sure bet, but I'd like to know whether it's something I have to do per specification or just a workaround for a bug in Opera.

                  推荐答案

                  正如评论中提到的,onerror网络级别出现故障时触发.如果错误仅存在于应用程序级别,例如,发送了 HTTP 错误代码,则 onload 仍然会触发.您需要在 onreadystatechange 处理程序中显式测试返回的状态代码.

                  As mentioned in the comments, onerror fires when there is a failure on the network level. If the error only exists on the application level, e.g., an HTTP error code is sent, then onload still fires. You need to test the returned status code explicitly in your onreadystatechange handler.

                  请注意,被拒绝的跨域请求也会触发 onerror 处理程序.

                  Note that a denied cross-domain request will also fire the onerror handler.

                  这篇关于XMLHttpRequest 的 onerror 处理程序应该何时触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:检测浏览器对跨域 XMLHttpRequests 的支持? 下一篇:如何将基本身份验证标头分配给 XMLHTTPREQUEST?

                  相关文章

                  最新文章

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

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

                    <legend id='vSvC8'><style id='vSvC8'><dir id='vSvC8'><q id='vSvC8'></q></dir></style></legend>
                  1. <small id='vSvC8'></small><noframes id='vSvC8'>

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