0

Hello i’m new to this community and to javascript too.

I want to create a function that will take a url as argument and return the htpp status code of that website. (404, 200, 403 etc).

function getStatus(url){

    var http = new XMLHttpRequest();

    http.open('HEAD',url, false);
    http.send();

    return http.status;
}

I tried this but isn’t working. Is there something else better than this that i can do i vanilla javascript.

Ps. The link that it says this question is already asked is not waht i wanted

Ahmin
  • 1
  • 1
  • 1
    You will only get that status *later* when the request has resolved, for which you need `onreadystatechange`: https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/onreadystatechange – deceze Mar 02 '21 at 06:57
  • You *will* need that duplicate link once you follow my above advice about `onreadystatechange`…! – deceze Mar 02 '21 at 07:00
  • Okay thanks I’ll try – Ahmin Mar 02 '21 at 07:01

0 Answers0