Whenever I need to test my internet connection, I rely on the following code snippet:
const checkInternetConnection = () => {
$('input').ajaxError(function(){
alert("failed");
});
$.get('http://www.google.com', function(data) {
alert("success");
});
}
To execute this functionality, I simply call the following function:
<input type="button" value="Click to report" onclick="checkInternetConnection()">
Unfortunately, no matter how many times I try, the result always shows 'Failed'.