There are two types of errors to be aware of using AJAX. The difference between them stems from the different perspectives.
The first type of error is seen from the perspective of the XMLHttpRequest object: Some factors prevent the request from being sent to the server, such as DNS cannot resolve the host name, the connection request is denied, or the URL is invalid.
The second type of error is the problem that is seen from the application's perspective: they occur when the request is successfully sent to the server, the server accepts the request, processes it, and generates a response, but the corresponding does not point to what you expect. For example, if the URL you requested does not exist, this type of problem can occur.
There are three ways to handle these errors, as shown in the following code:
<! DOCTYPE html>
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
JavaScript handles AJAX errors