Question

I am really new to ajax and jquery, so please bear with me. I am currently building a small application that will do the basic task of telling you a website's status code, and doing something based on the code that is returned. I found this code online, and it returns "Page not found" if the http status code is 404.

$(function() {
      var url = "http://www.google.com";
      $.ajax(url,
      {
         statusCode: {
         404: function() {
            alert('page not found');
         }
      }
   });   
});

But, instead of checking for a 404 status code, how can I save the raw status code value to a variable?
Thanks!

Was it helpful?

Solution

Hope something like this might help u mate.. :)

 error:function (xhr, ajaxOptions, thrownError){
          alert(xhr.status); 
           switch (xhr.status) {
              case 404:
                    // Desired Action.
              }
        } 

    complete: function(xhr, statusText){
           alert(xhr.status); 
    }

U may get quite lot of information in the below link mate

http://api.jquery.com/jQuery.ajax/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top