For my web app I need a way to detect whether the application has lost the connection to the IP address (100.100.100.100) it runs on or whether the device has connected to a different network/connection. This must all be done client side. Currently I am doing the following but it doesn’t seem to work. Any ideas how to accomplish this? Thanks.
$.ajax({
type: "GET",
url: "100.100.100.100",
success: function(){
alert("Connection Good!")
}
error: function(XMLHttpRequest, textStatus, errorThrown){
if(textStatus == 'timeout') {
alert("Connection has been lost.");
}
}
});
It’s not going to work to a random IP address due to the same-origin policy. The best the thing to do is to have a request to a URL on the server your app is served from (i.e. same Authority as the JS file comes from) which gives a known good response.
** Update
Just to be clear, by ‘Authority’ I really mean host, port, and protocol. So for example, http://google.com is not the same as https://google.com nor is it the same as http://google.com:8080