我有以下javascript代码,我想通过使用javascript获取HTTP 403 Forbidden响应代码,我尝试使用以下代码并对其进行修改,但它不适用于我..
<script type="text/javascript">
var request = new XMLHttpRequest();
request.open('GET', 'https://domain.com/file', true);
request.send();
request.onreadystatechange = function(){
if (request.status === 403) {
alert("Oh no, it does not exist!");
}
};
</script>
答案 0 :(得分:0)
首先,我会尝试添加readyState
支票,如下所示:
var request = new XMLHttpRequest();
request.open('GET', 'https://domain.com/file', true);
request.onreadystatechange = function(){
if (request.readyState === 4) {
if (request.status === 403) {
alert("Oh no, it does not exist!");
}
}
};
request.send();
这可以解决吗?