Skip to content Skip to sidebar Skip to footer

Can Jquery/js Help Me Determine If An Url Exists

I can't figure out wheater or not, jQuery/Ajax can help me determine if a given URL is online. What I really is looking for is the HTTP status code of a http connnection to the URL

Solution 1:

This is not possible inside of the browser but if you were to make an ajax request to your webserver, you could ask it do do the verification.

Client Code

$.ajax({
    url: "urltest.py",
    cache: false, 
    dataType: "text"success: function(data){
        if(data === "SUCCESS"){
        //do things
        } else {
        //else do other things
        }
    }
});

Server code

defcall_server(self, url):
    headers = {'Content-Type': 'application-json'
              , 'Accept' : 'application-json'
              , 'Accept-Encoding' : 'gzip, deflate'
              }
    r = requests.get(url)
    if r.status_code == 200:
        print"SUCCESS"else:
        print"No soup for you"

Hasn't been tested or anything, but you get the idea.

Post a Comment for "Can Jquery/js Help Me Determine If An Url Exists"