Does anyone know of a good function or a good way to check for an internet connection before making an ajax request?
Does anyone know of a good function or a good way to check for an internet connection before making an ajax request?
It's possible, try:
var online = navigator.onLine; // true ou false, (há, não há conexão à internet)
if(online) {
// efetuar pedido ajax
}
To test, create a file on your computer, eg: online.html and type:
<script>
var online = navigator.onLine;
alert(online);
</script>
Open it in the browser and disconnect / connect the connection to test