I am trying to check if a URL exists or not. But I am caught by CORS - This is what I tried:
<!DOCTYPE html>
<html>
<head>
<script>
function checkUrl(url){
var request = new XMLHttpRequest;
request.open('GET', url, true);
request.send();
request.onreadystatechange = function(){
if(request.readyState==4){
if(request.status==200){
console.log(request.readyState);
return true;
}
}else{
return false;
}
}
};
var url = 'http://localhost:' + 8080 + '/hello/';
if(checkUrl(url)){
alert('Success');
}else{
alert('Failure');
}
</script>
</head>
<body>
</body>
</html>
I am getting the error: Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://localhost:8080/hello/. (Reason: CORS header 'Access-Control-Allow-Origin' missing).
Note: I have a limitation: I wont be able to use any Ajax/jQuery related code.
Please let me know how to resolve this.