如何从JavaScript检测HTTP状态 [英] How to detect HTTP status from JavaScript

查看:131
本文介绍了如何从JavaScript检测HTTP状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在一个脚本中检测到,可以部署在我的控制之外,该页面是否具有HTTP状态200,404或500等。



解决方案

让页面自己创建一个XMLHttpRequest(使用 location.href document.URL ),并检查您获得的HTTP状态。似乎是相当便携的方式对我来说。为什么你会做这样的事情是超出我的理解,但是,)


I want to detect in a script, which could be deployed beyond my control, whether the page was delivered with a HTTP status of 200, 404 or 500 etc.

This can't be done, right?

解决方案

Have the page make a XMLHttpRequest to itself (using location.href or document.URL) and check the HTTP status you get. Seems to be pretty portable way to me. Why you would do a thing like this is beyond my understanding though ;)

这篇关于如何从JavaScript检测HTTP状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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