13

I am utilising the callback function of jQuery's .load method to run certain code if the textStatus parameter of the .load method is equal to a certain string.

e.g. I have

jQuery("#myContainer").load('/seperate-file-with-content.asp', function(responseText, textStatus, xhr){                     
    if (textStatus === "error" || responseText.length <= 0) {
        //file failed to load i.e. textStatus == error 
        //or file loaded but has no content
    } else {
        //file loaded successfully i.e. textStatus == success
    }       
});

But i'm worried that the else part of the if statement may catch other non expected textStatus values that aren't equal to success.

Are there any other possible values to textStatus, other than error and success ?

EDIT/UPDATE: As I now believe that .load is based on .ajax, the answers in the following question may be of use for anyone else with a similar question:- In jQuery's ajax success callback, will textStatus ever not be "success"?

Community
  • 1
  • 1
Dave Haigh
  • 4,369
  • 5
  • 34
  • 56

1 Answers1

20

load() is based on $.ajax(), and the documentation for this method lists the possible statuses as:

  • abort
  • error
  • notmodified
  • parsererror
  • success
  • timeout
Frédéric Hamidi
  • 258,201
  • 41
  • 486
  • 479
  • apart from error and success, do you know how I could replicate the above statuses on my page? – Dave Haigh Jun 19 '12 at 15:24
  • 1
    `abort` won't be easy, since `load()` does not return a jqXHR (although `$.ajax()` does), so you cannot abort it to obtain that status. `timeout` is easy to get (have the server hang on the request), as are `notmodified` (have the server reply `304 Not Modified`) and `parsererror` (have the server send invalid markup or JSON). – Frédéric Hamidi Jun 19 '12 at 15:31
  • thanks for the help, you've answered my original question and more. – Dave Haigh Jun 19 '12 at 15:32
  • 1
    I also got a "nocontent" as the textStatus from a $.getJson request. – Warrick Apr 12 '16 at 02:27
  • See "complete" and "error" sections in the jquery ajax documentation https://api.jquery.com/jQuery.ajax/ – mortenma71 Jul 08 '20 at 08:00