I define a link <a href="http://www.example.com">Hello</a>.when i click this link javascript should check the link is exist/valid.if true,the page should be load or the page should resirect to another page.i am using javascript ajax to check the page exist/not.i am using the condition xmlhttp.status == 200.But it is not working.here is the code:
function check(url){
xmlHttp.open("GET", url, true);
xmlHttp.onreadystatechange=function(){
if(xmlHttp.readyState==4){
if (xmlHttp.status==200)
{
alert("Page Available");
}
else
{
window.location.href= "http://www.hello.com";
}
}
}
xmlHttp.send(null);
}
</script>
</head>
<body>
<a href="http://www.example.com" onclick="check(this)">Click this Link</a>
here xmlHttp.status==200 is not working.can anyone help me?