Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get information back from an Ajax call when internet connectivity is lost

I have the following:

 $.ajax({ cache: false,
    url: "/Admin/Contents/GetData",
    data: { accountID: AccountID },
    success: function (data) {
        $('#CityID').html(data);
    },
    error: function (ajaxContext) {
        alert(ajaxContext.responseText)
    }
});

When I lose connectivity to the internet the error is called but I don't see anything in the responseText.

Is there a way I can find out different kind of errors based on status information in the returned ajaxContent? I would really like to be able to put out a message saying "Internet connectivity lost" and another message if there is some other problem.

like image 344
Alan2 Avatar asked Jun 07 '12 11:06

Alan2


1 Answers

According to the jQuery docu the error function receives three arguments:

  1. jqXHR:
  2. textStatus: a string describing the type of error that occurred
  3. errorThrown: an optional exception object, if one occurred

Furthermore it states:

Possible values for the second argument (besides null) are "timeout", "error", "abort", and "parsererror". When an HTTP error occurs, errorThrown receives the textual portion of the HTTP status, such as "Not Found" or "Internal Server Error."

So you might want to have a look at the content of the second adn third parameter.

like image 140
Sirko Avatar answered Oct 23 '22 05:10

Sirko