In my JavaScript code, I am attempting to retrieve a 403 Forbidden response code using JavaScript. I have tried modifying the following code, but it does not seem to be working for me:
<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>