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!

3
  • 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. Commented Nov 11, 2013 at 17:18
  • @Qǝuoɯᴉs That's not good! What happened? Commented Nov 29, 2013 at 18:32
  • to study, and work. chat is a real waste of time. I hope all is good with you. Commented Nov 29, 2013 at 18:35

1 Answer 1

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/

Sign up to request clarification or add additional context in comments.

3 Comments

So like this then? Or am i doing it all wrong pastebin.com/TxbM58b1 sorry, im really new
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...
hope the following link might help u with ur doubts mate. stackoverflow.com/questions/2000609/jquery-ajax-status-code-0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.