Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to tell the user that there's no internet connection when they press submit? [duplicate]

Assuming there is no internet connection, of course. Like a jQuery method?

like image 403
Doug Smith Avatar asked Dec 21 '22 15:12

Doug Smith


1 Answers

I would try to make HEAD requests (no content downloaded) to a few servers you know are online. They will automatically fail if there is no network (no need to set a timeout).

$.ajax({
    type: "HEAD",
    url: 'http://www.google.com',
    error: function() {
        alert('world is gone !');
    }
});

DEMONSTRATION (unplug your network to test)

like image 176
Denys Séguret Avatar answered Feb 01 '23 22:02

Denys Séguret