How to detect HTTP status from JavaScript

后端 未结 4 1746
没有蜡笔的小新
没有蜡笔的小新 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:22

    Page A can be a Javascript that loads page B via AJAX and displays it with document.write or in a pop up window or however.

    In such a strategy, you can check return code for success/failure in the AJAX handler and send different things to the output window depending on status.

    Most Ajax libraries provide a way to examine the return code....

    See for instance "transport.status" with Ajax.Request in Prototype.js

提交回复
热议问题