I am trying to append an image to a page using JavaScript:
image = document.createElement('img');
image.onload = function(){
document.body.appendChild(image);
}
image.onerror = function(){
//display error
}
image.src = 'http://example.com/image.png';
The user must be authenticated to see this image, and if they are not, I want to display an error message. Unfortunately, the server is not returning an HTTP error message, but rather redirect the request to a (mostly) empty page, so I am getting an HTTP 200
, but the warning Resource interpreted as Image but transferred with MIME type text/html
and nothing is displaying.
How can I handle this case? I don't have the ability to change what the webserver serves up if the user isn't authenticated.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…