Search code examples
jqueryexceptionhttpwebrequest

Return the 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 loads the return data correctly. If I get a 500 error, it does not. Is there a way to output the failed request message information as well?

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

I can see it in firebug, but would like to load it onto my page.


Solution

  • From 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);
      }
    });