Update: The server may be offline, and OP want to retry when Ajax request is timed out.
To "fix" this issue, you can wrap http.send()
statement into a try-catch
block, such as:
...
try {
http.send();
} catch(e) {
//e.name would be "NetworkError" if the server is offline.
console.log(e);
}
If "NetworkError" is caught, server-offline is detected, and Ajax request can be retried some time later.
There are 3 problems in this issue:
According to the error screenshot (net::ERR_CONNECTION_TIMED_OUT
), the target server (http://192.168.1.10/
) does not respond. Please check whether it is accessible.
In the code, the Content-Type
is defined as application/x-www-form-urlencoded
, which means a form is submitted. However, the Ajax request is a GET
request without any data-sending logic. It is a pretty weird combination and can be refused by browser or server side logic. If you just want to play with Ajax GET request, it is not necessary to configure Content-Type.
The load
event (http.onload
in the question) of XMLHttpRequest
is not supported well, please use onreadystatechange
suggested by @Katie.