J
Jake Barnes
Curious about this code snippet on jibbering.com:
xmlhttp.open("HEAD", "/faq/index.html",true);
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4) {
if (xmlhttp.status==200) alert("URL Exists!")
else if (xmlhttp.status==404) alert("URL doesn't exist!")
else alert("Status is "+xmlhttp.status)
}
}
xmlhttp.send(null)
I tried to turn this into a function:
function checkUrlValidity(url) {
if (null) {
var xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
} else {
var xmlhttp=new XMLHttpRequest();
}
xmlhttp.open("HEAD", url, true);
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4) {
if (xmlhttp.status==200) alert("URL Exists!");
else if (xmlhttp.status==404) alert("URL doesn't exist!");
else alert("Status is "+xmlhttp.status);
}
}
xmlhttp.send(null)
}
Two problems:
I could not figure out the right syntax for testing for ActiveXObject.
I could not figure out what the url is suppose to look like. When I try
this:
checkUrlValidity("www/monkeyclaus.org");
the script returns a 404 error, even thought that is a legit address.
So if I try this:
checkUrlValidity("http://www/monkeyclaus.org/index.php");
I get "Uncaught exception: Permission denied for 'open'".
xmlhttp.open("HEAD", "/faq/index.html",true);
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4) {
if (xmlhttp.status==200) alert("URL Exists!")
else if (xmlhttp.status==404) alert("URL doesn't exist!")
else alert("Status is "+xmlhttp.status)
}
}
xmlhttp.send(null)
I tried to turn this into a function:
function checkUrlValidity(url) {
if (null) {
var xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
} else {
var xmlhttp=new XMLHttpRequest();
}
xmlhttp.open("HEAD", url, true);
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4) {
if (xmlhttp.status==200) alert("URL Exists!");
else if (xmlhttp.status==404) alert("URL doesn't exist!");
else alert("Status is "+xmlhttp.status);
}
}
xmlhttp.send(null)
}
Two problems:
I could not figure out the right syntax for testing for ActiveXObject.
I could not figure out what the url is suppose to look like. When I try
this:
checkUrlValidity("www/monkeyclaus.org");
the script returns a 404 error, even thought that is a legit address.
So if I try this:
checkUrlValidity("http://www/monkeyclaus.org/index.php");
I get "Uncaught exception: Permission denied for 'open'".