最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - What HTTP status codes fire error event on XMLHttpRequest - Stack Overflow

programmeradmin1浏览0评论

I've read every spec I can find, even the W3 for ProgressEvents as well as XMLHttpRequest, and I'm finding diddly regarding WHICH status codes (or What response) fire an Error event on an async XHR request. The most I can find is references to checking the status code itself on the object and handling that, which normally treats anything but 200 as an Error, yet a 3xx redirect from, say, a POST is not an Error (I can't recall if the XHR will follow a redirect automatically) Can someone help me out or point me in the right direction regarding the spec (no libraries) for all responses that initiate an onerror event?

I've read every spec I can find, even the W3 for ProgressEvents as well as XMLHttpRequest, and I'm finding diddly regarding WHICH status codes (or What response) fire an Error event on an async XHR request. The most I can find is references to checking the status code itself on the object and handling that, which normally treats anything but 200 as an Error, yet a 3xx redirect from, say, a POST is not an Error (I can't recall if the XHR will follow a redirect automatically) Can someone help me out or point me in the right direction regarding the spec (no libraries) for all responses that initiate an onerror event?

Share Improve this question edited Nov 11, 2020 at 22:41 Brian Tompsett - 汤莱恩 5,89372 gold badges61 silver badges133 bronze badges asked Jan 24, 2013 at 1:40 user10795user10795 2233 silver badges10 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 7

onerror only fires for network-level events, which means that onload will fire if there is a successful response, regardless of HTTP status code. See this question for more discussion: When should XMLHttpRequest's onerror handler fire

发布评论

评论列表(0)

  1. 暂无评论