Johnson
Johnson

Reputation: 818

jQuery Ajax Call, give offline/ "not able to connect" message

Yes, i have a normal ajax call that calls imback.php, that checks for new stuff if you have been blur for 50 sec.

Now if you disconnects from the internet, and when you get on focus, it will not be able to get imback.php.(i think its 404 error) So i would like to make a offline msg/timeout thing, so it alerts "You have no internet connection or something else went wrong".

How can i do that?

           $.ajax({
                url: 'imback.php', 
                success:function(msg) {
$('.NewStuffSinceActive').prepend(msg);

                }
            })

Upvotes: 0

Views: 670

Answers (1)

Nick Craver
Nick Craver

Reputation: 630349

You can use the error callback for this:

$.ajax({
  url: 'imback.php', 
  success: function(msg) {
    $('.NewStuffSinceActive').prepend(msg);
  },
  error: function(xhr, status, error) {
    alert("An error occured: " + error);
  }
})

Upvotes: 1

Related Questions