enter image description here I have a requirement in my project ,where I need to the check the URL is working or not in Javascript. If that URL is working in need to get 200 response code
I tried this code,with this code I getting error. I am not getting 200 response
function checkLink(url) {
var http = new XMLHttpRequest();
http.open('GET',url, true);
http.setRequestHeader("Access-Control-Allow-Origin","https://vivr.pgf-life.co.jp/1/top");
http.setRequestHeader("Access-Control-Allow-Methods", "GET,POST,PUT");
http.setRequestHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
http.send();
console.log("status=",http.status);
if(http.status===404)
return false;
else
return true;
}
var a=checkLink("https://www.google.com/")
console.log(a);