jQuery.ajax gives “TypeError: Cannot read property 'documentElement' of null” on server but not local

前端 未结 1 1151
渐次进展
渐次进展 2020-12-18 10:31

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 f

相关标签:
1条回答
  • 2020-12-18 11:06

    The error is thrown from the ajax call:

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

    Since you are expecting a XML dataType, the call for "ajax/home.html" url will return a mime type "text/html". You might want to omit the dataType totally for jQuery's intelligent guess to kick in. E.g.:

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

    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' />");
        }
    }
    
    0 讨论(0)
提交回复
热议问题