【发布时间】:2012-04-06 05:33:04
【问题描述】:
我正在尝试使用 JavaScript 将图像附加到页面:
image = document.createElement('img');
image.onload = function(){
document.body.appendChild(image);
}
image.onerror = function(){
//display error
}
image.src = 'http://example.com/image.png';
用户必须经过身份验证才能看到此图像,如果不是,我想显示一条错误消息。不幸的是,服务器没有返回 HTTP 错误消息,而是将请求重定向到(大部分)空页面,所以我收到了 HTTP 200,但警告 Resource interpreted as Image but transferred with MIME type text/html 并没有显示任何内容。
我该如何处理这种情况?如果用户未通过身份验证,我无法更改网络服务器提供的内容。
【问题讨论】:
标签: javascript error-handling mime-types