毕竟,对于异步请求,以与同步请求相同的方式处理错误是最佳的用户体验。只有
function handleXhrError(xhr) { document.open(); document.write(xhr.responseText); document.close();}当您也
<script>需要加载和初始化元素时,它将在IE6 / 7/8中失败。IE6 /
7/8不会那样做。为了使IE能够做到这一点,您基本上需要保留当前
<head>元素,并仅用替换其子元素
$("head").html(newHead)。应该对该<body>元素执行相同的操作。
function handleXhrError(xhr) { var newdocument = xhr.responseText; $("head").html(newdocument.substring(newdocument.indexOf("<head>") + 6, newdocument.indexOf("</head>"))); $("body").html(newdocument.substring(newdocument.indexOf("<body>") + 6, newdocument.indexOf("</body>")));}讨厌,但是
$(xhr.responseText)当响应文本表示带有头部和正文的整个HTML文档时,则无法执行。当您
<body>在错误页面模板中具有某些属性(例如ID,类等)时,请不要忘记相应地更改子字符串索引。



