I am currently working on testing the functionality of a given URL using Ajax. In order to achieve this, I made some modifications to the Ajax code.
function checkURLStatus()
{
var xmlhttp;
if (window.XMLHttpRequest)
{
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{
// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4)
{
document.getElementById("myDiv").innerHTML=xmlhttp.status;
}
}
xmlhttp.open("GET","wrongurl",true);
xmlhttp.send();
}
My goal is to have the status displayed as 404 or 503 when the URL is incorrect. However, the desired output is not achieved. Are there any suggestions to rectify this issue?