Can jQuery / js help me determine if a url exists

I can't figure out what is happening or not, jQuery / Ajax can help me determine if a given URL is available.

What I'm really looking for is the http connection status code of the http to the url, but maybe too much to ask?

The URLs are the user input, and therefore I am unable to change the environment on the server I am connecting to.

Every help is more than welcome.

+1
javascript jquery
source share
1 answer

This is not possible in the browser, but if you have to make an ajax request to your web server, you can ask him to do a check.

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

 def call_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" 

Not tested or anything else, but you understood the idea.

+1
source share

All Articles