jQuery.ajax给人"类型错误:无法读取属性的空&QUOT'documentElement';在服务器上而不是本地 [英] jQuery.ajax gives "TypeError: Cannot read property 'documentElement' of null" on server but not local

查看:189
本文介绍了jQuery.ajax给人"类型错误:无法读取属性的空&QUOT'documentElement';在服务器上而不是本地的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 http://alpha.spherecat1.com/ <有我的jQuery的code的一个问题/一>,但本地副本工作正常。正如你可以看到,如果你现在访问的网站,Ajax调用提供了以下错误:

I'm having a problem with my jQuery code on http://alpha.spherecat1.com/, but the local copy works fine. As you can see if you visit the site now, the ajax call gives the following error:

类型错误:无法读取的空性'documentElement'

"TypeError: Cannot read property 'documentElement' of null"

我检查和复查,并重新上传一切我能想到的。该文件称,以确保我发送正确的MIME类型,我也没有用。这里是有问题的code:

I've checked and rechecked and reuploaded everything I can think of. The documentation said to make sure I was sending the right MIME type, which I did to no avail. Here's the offending code:

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。它抓住网页是在previous网址/ AJAX文件夹中看到。任何帮助,您可以提供将大大AP preciated!

It then goes on to render the page into a div. The pages it's grabbing are visible in the /ajax folder at the previous url. Any help you can provide would be greatly appreciated!

推荐答案

该错误是由Ajax调用抛出:

The error is thrown from the ajax call:

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

既然你期待一个XML数据类型,呼吁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 我以为是调试:

You also have the following alert() in appendCSS which I assume is for debugging?:

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

这篇关于jQuery.ajax给人&QUOT;类型错误:无法读取属性的空&QUOT'documentElement';在服务器上而不是本地的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆