jQuery.ajax在服务器上给出了“TypeError:无法读取null的属性’documentElement’,但不是本地的

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

“TypeError:无法读取属性’documentElement’的null”

我已经检查并重新检查并重新上载了我能想到的一切。 该文档说,以确保我发送正确的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 dataType,因此对“ajax / home.html”url的调用将返回mime类型“text / html”。 您可能想要完全省略dataType以获得jQuery的智能猜测 。例如:

 $.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(""); } }