Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTTP Status Code from URL in Javascript

I'm trying to find a function that return HTTP Status Code from an URL, and then "make something" based on the returned statuses (404, 416, 200 etc...)

Can someone help me? I've tried the other functions posted here on StackOverflow but anyone was usefull for my purpose.

I need to integrate this function inside my PlayFramework web-app.

Thanks a lot

like image 292
Fabio Avatar asked Feb 10 '26 01:02

Fabio


1 Answers

Can you try the following ..?

function getStatus(url) {
        var request = new XMLHttpRequest();
    request.onreadystatechange = function() {
        if (request.readyState === 4){
            request.status;//this contains the status code
        }
    };
request.open("GET", url , true);
request.send(null);
}
like image 189
Noushad Avatar answered Feb 12 '26 14:02

Noushad



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!