gpt4 book ai didi

javascript - jQuery.ajax 给出 "TypeError: Cannot read property ' documentElement' of null"on server but not local

转载 作者:数据小太阳 更新时间:2023-10-29 02:03:23 25 4
gpt4 key购买 nike

我在 http://alpha.spherecat1.com/ 上的 jQuery 代码有问题,但本地副本工作正常。如您所见,如果您现在访问该站点,ajax 调用会出现以下错误:

“类型错误:无法读取 null 的属性‘documentElement’”

我检查并重新检查并重新上传了我能想到的所有内容。文档说要确保我发送的是正确的 MIME 类型,但我没有这样做。这是有问题的代码:

function changePageAJAX(newPage, method)
{
if (method != "replace")
{
window.location.hash = newPage;
}
newPage = newPage.substring(1); // Remove the hash symbol.
title = "SphereCat1.com | " + fixCase(newPage.replace(/\//g, " > ")); // Set the window title.
newPage = "ajax/" + newPage + ".html"; // Add path.
if (newPage == currentPage)
{
return; // Don't let them load the current page again.
}
$.ajax({ // jQuery makes me feel like a code ninja.
url: newPage,
dataType: "xml",
success: function(data, status, xmlhttp){ renderPage(xmlhttp); },
error: function(xmlhttp, status, error){ alert(error); renderPage(xmlhttp); }
});
document.title = title;
currentPage = newPage;
}

然后它继续将页面渲染到一个 div 中。它抓取的页面在前一个 url 的/ajax 文件夹中可见。如果您能提供任何帮助,我们将不胜感激!

最佳答案

错误是从 ajax 调用中抛出的:

error: function(xmlhttp, status, error)...

由于您需要 XML 数据类型,因此对“ajax/home.html”url 的调用将返回一个 mime 类型“text/html”。对于 jQuery 的 intelligent guess,您可能希望完全省略数据类型。开始。例如:

$.ajax({ // jQuery makes me feel like a code ninja.
url: newPage,
success: function(data, status, xmlhttp){ renderPage(xmlhttp); },
error: function(xmlhttp, status, error){ alert(error); renderPage(xmlhttp); }
});

您在 appendCSS 中还有以下 alert(),我认为它用于调试?:

function appendCSS(filename)
{
alert(filename);
if (filename != null)
{
$("head").append("<link rel='stylesheet' id='extracss' href='"+filename+"' type='text/css' />");
}
}

关于javascript - jQuery.ajax 给出 "TypeError: Cannot read property ' documentElement' of null"on server but not local,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2189214/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com