Get current page http status from javascript

2019-01-14 10:38发布

Is there any way to get the http status of the current web page from javascript?

Spent some time searching on the web, but no luck at all... Seems like it's not possible, but wanted to check with StackOverflow for maybe some fancy workaround.

(Providing it from the server as part of the response body is not acceptable, the status is supposed to be only available via the http header)

3条回答
淡お忘
2楼-- · 2019-01-14 11:13

This is not in any way possible, sorry.

查看更多
3楼-- · 2019-01-14 11:18

you can only check status of page loading try:var x = document.readyState; The result of x could be: One of five values:

uninitialized - Has not started loading yet
loading - Is loading
loaded - Has been loaded
interactive - Has loaded enough and the user can interact with it
complete - Fully loaded
查看更多
狗以群分
4楼-- · 2019-01-14 11:21

It is not beuatfull, but you can use

t = jQuery.get(location.href).success(function (){console.log(t.status)}).error(function(){console.log(t.status)})
查看更多
登录 后发表回答