2

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!

pattyd
  • 5,927
  • 11
  • 38
  • 57
  • 2
    Hey @pattyd seems your question is solved. Anyway, I'm on self-suspension for the next three months, if you ping me I can read your messages but I can't chat :L good luck with your studies. – samayo Nov 11 '13 at 17:18
  • @Qǝuoɯᴉs That's not good! What happened? – pattyd Nov 29 '13 at 18:32
  • to study, and work. chat is a real waste of time. I hope all is good with you. – samayo Nov 29 '13 at 18:35

1 Answers1

3

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/

Nibin
  • 3,922
  • 2
  • 20
  • 38
  • So like this then? Or am i doing it all wrong http://pastebin.com/TxbM58b1 sorry, im really new – pattyd Nov 11 '13 at 02:40
  • How would i also get this to work for checking the status of an external link, example: www.google.com? If i put google.com/alksdjlaksjdlkjasdlkj.jpg it says 0, which means its reachable... – pattyd Nov 11 '13 at 03:12
  • hope the following link might help u with ur doubts mate. http://stackoverflow.com/questions/2000609/jquery-ajax-status-code-0 – Nibin Nov 11 '13 at 04:44