Return 500 error message using jQuery.load () or .get ()

I am trying to make AJAX calls using the jQuery.load () method. When the request passes, it correctly loads the returned data. If I get a 500 error, it is not. Is there a way to display error information with an error message?

$("#activity").load("/forumsetup", { id:myid }, 
       function(data) {
          $("#restart").css("visibility","visible");
        });  

I see this in firebug, but I want to upload it to my page.

+3
source share
2 answers

From the jQuery doc page: http://api.jquery.com/load/

$("#success").load("/not-here.php", function(response, status, xhr) {
  if (status == "error") {
    var msg = "Sorry but there was an error: ";
    $("#error").html(msg + xhr.status + " " + xhr.statusText);
  }
});
+10
source

Yes, jquery returns an object in xhr. You need to access it as follows:

$("#success").load("/not-here.php", function(response, status, xhr) {
if ( status == "error" ) 
{
 if (xhr.status == 500 )
  do something...

for more information check: http://api.jquery.com/jQuery.ajax/#jqXHR

0

All Articles