frosty
frosty

Reputation: 5370

how to return 404 status in jquery

I call the load method. There are some occasions when the page it calls does not exist. In firebug I can see the 404 status is returned. How can I access this status in jQuery so I can handle it?

$("#section-main-wrapper").load(uri);

Upvotes: 1

Views: 332

Answers (3)

Joshua Partogi
Joshua Partogi

Reputation: 16425

$.ajax({
  url: uri,
  cache: false,
  success: function(html){
    $("#section-main-wrapper").replaceWith(html);
  },

  error: function (XMLHttpRequest, textStatus, errorThrown) {
    // Do something here
    this; 
  }  
});

Upvotes: 1

Ondra Žižka
Ondra Žižka

Reputation: 46796

http://docs.jquery.com/Ajax/load

$(...).load(url, null, function (responseText, textStatus, XMLHttpRequest) cb {
  this; // dom element
});

Upvotes: 1

Richard Szalay
Richard Szalay

Reputation: 84744

Pass in a callback function:

$("#section-main-wrapper").load(uri, null, function(response, status, xhr) {
    // Check status
});

Upvotes: 4

Related Questions