Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What HTTP status codes fire error event on XMLHttpRequest

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?

like image 897
user10795 Avatar asked Jan 24 '13 01:01

user10795


People also ask

How do I check XMLHttpRequest status?

The read-only XMLHttpRequest. status property returns the numerical HTTP status code of the XMLHttpRequest 's response. Before the request completes, the value of status is 0. Browsers also report a status of 0 in case of XMLHttpRequest errors.

How do I fix XMLHttpRequest error?

To Solve Flutter Web getting 'XMLHttpRequest' error while making HTTP call Error Most cases of this error just add Access-Control-Allow-Origin value in the header might resolve the issue. Just make sure to replace all Underscore by Dash.

What is XMLHttpRequest error?

This error is a Javascript error and it can be inspected from AndroidStudio terminal or from the browser console. If you run into this problem it means that the requests to the API server are failing due to a CORS error.

How to get the status code of the XMLHttpRequest response?

The read-only XMLHttpRequest.status property returns the numerical status code of the response of the XMLHttpRequest. status will be an unsigned short. Before the request is complete, the value of status will be 0.

How do XMLHttpRequest error events work?

It successfully contacted the server, the server reported that the resource wasn't found, the XMLHttpRequest instance properly received that report -- everything went fine. The error event only fires if something goes wrong with forming, parsing, or transmitting requests and responses, not if the response happens to be something you didn't want.

What are the HTTP response status codes?

HTTP response status codes indicate whether a specific HTTP request has been successfully completed. Responses are grouped in five classes: Informational responses (100–199) Successful responses (200–299) Redirects (300–399) Client errors (400–499) Server errors (500–599)

How does the read-only XMLHttpRequest property work?

The read-only XMLHttpRequest.status property returns the numerical HTTP status code of the XMLHttpRequest's response. Before the request completes, the value of status is 0. Browsers also report a status of 0 in case of XMLHttpRequest errors.


1 Answers

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

like image 123
monsur Avatar answered Oct 14 '22 21:10

monsur