How to detect HTTP status from JavaScript

后端 未结 4 1666
没有蜡笔的小新
没有蜡笔的小新 2020-12-25 14:59

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 don

4条回答
  •  被撕碎了的回忆
    2020-12-25 15:37

    Why does the javascript need to know this? Sounds like it would make more sense just to embed it on a custom 404 page. No need to detect HTTP status of the parent page (I don't think it's possible - maybe doing an ajax call to itself after each load, but that's just silly). if the code is being executed, its guaranteed to be a 404

提交回复
热议问题