我正在尝试使用JavaScript将图像附加到页面:
image = document.createElement('img');
image.onload = function(){
document.body.appendChild(image);
}
image.onerror = function(){
//display error
}
image.src = 'http://example.com/image.png';
Run Code Online (Sandbox Code Playgroud)
必须对用户进行身份验证才能看到此图像,如果不是,我想显示错误消息.不幸的是,服务器没有返回HTTP错误消息,而是将请求重定向到(大多数)空页面,所以我得到了一个HTTP 200,但警告Resource interpreted as Image but transferred with MIME type text/html并没有显示任何内容.
我该如何处理这个案子?如果用户未经过身份验证,我无法更改Web服务器所提供的内容.