Answer the question
In order to leave comments, you need to log in
XMLHttpRequest in try catch safari (local)
try {
this.xmlHttpRequest = new XMLHttpRequest();
this.xmlHttpRequest.onreadystatechange = this.onReadyStateChangeHandler_;
this.xmlHttpRequest.open('GET', this.url, this.async_);
this.xmlHttpRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded;');
this.xmlHttpRequest.send(null);
} catch(error) {
Alert('error')
}
When opening a channel to a file this.xmlHttpRequest.open('GET', this.url, this.async_);
, if:
1. The request is asynchronous;
2. Loading happens in locale;
3. The file at the specified url is missing;
4. Safari browser || Chrome (latest version).
The try catch block does not work, XMLHttpRequest calls onreadystatechange with readyState == 4, status == 0, statusText=='', responseText==''.
Tell me how to overcome and catch the error of not correct url with an asynchronous request.
Answer the question
In order to leave comments, you need to log in
Also encountered, in Chrome, when writing extensions. As a result, I caught status == 0 && responseText == "". Very interesting.
www.w3.org/TR/XMLHttpRequest/#the-send-method
In theory, what you are describing is a network error. And network error should be handled like this:
When something is said to be a network error run the request error steps for exception NETWORK_ERR.
Let's see what happens with a request error:
When something is said to be a request error for exception exception run these steps:
<...>
If the asynchronous flag is false raise an exception exception and terminate the overall set of steps.
Those. Chrome, Safari, Firefox work correctly without throwing an error if the request is asynchronous. IE and Opera do not.
To catch the error, you need to handle the readystatechange event, yes.
Correct me if I'm wrong.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question