This is not how AJAX works. AJAX is fundamentally asynchronous (which actually means the first “A”), which means rather than calling the function and returning the value, you are calling the function and passing the callback, and that callback will be called with the value.
(see http://en.wikipedia.org/wiki/Continuation_passing_style .)
What do you want to do after you know if the URL is responding or not? If you intended to use this method as follows:
//do stuff var exists = urlExists(url); //do more stuff based on the boolean value of exists
Then you need to do the following:
//do stuff urlExists(url, function(exists){ //do more stuff based on the boolean value of exists });
where urlExists() :
function urlExists(url, callback){ $.ajax({ type: 'HEAD', url: url, success: function(){ callback(true); }, error: function() { callback(false); } }); }
Han seoul-oh
source share