Here is some code I am working with:
var req = new XMLHttpRequest();
req.onload = function(){
if (req.status === "200"){
doSomethingWithTheReceivedData();
}
else {
alert("Error msg");
}
};
When running index.html directly from my computer without a server, I encountered the error "NS_ERROR_DOM_BAD_URI: Access to restricted URI denied" in the Firefox web console. This is because the script was trying to access a relative path that is only available on the server, not locally on my computer. Now, I need to properly handle this error situation as currently, clicking the button triggering this code does nothing. Despite adding a status code check, it doesn't seem to address this particular issue. I assume no request is returned in this case. So, how can I effectively manage and respond to this error?