来自Java脚本中URL的HTTP状态代码 [英] HTTP Status Code from URL in Javascript

查看:79
本文介绍了来自Java脚本中URL的HTTP状态代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试找到一个从URL返回HTTP状态代码的函数,然后根据返回的状态(404、416、200等)创建某些东西"

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...)

有人可以帮助我吗?我已经尝试过这里发布在StackOverflow上的其他函数,但是任何人都对我有用.

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

我需要将此功能集成到我的PlayFramework网络应用程序中.

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

非常感谢

推荐答案

您可以尝试以下..吗?

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);
}

这篇关于来自Java脚本中URL的HTTP状态代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆