`
南山忍者
  • 浏览: 83498 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

HierarchyRequestError: Node cannot be inserted at the specified point in the

阅读更多

     

         在使用$.get()方法时,出现了以上的错误信息:

         HierarchyRequestError: Node cannot be inserted at the specified point in the  hierarchy

 

        下面是我的源代码:

 

$(document).ready(function() {
  var pageNum = 1;
  $('#more-photos').click(function() {
    var $link = $(this);
    var url = $link.attr('href');
    if (url) {
      $.get(url, function(data) {
        $('#gallery').append(data);
      });
      pageNum++;
      if (pageNum < 20) {
        $link.attr('href', 'pages/' + pageNum + '.html');
      }
      else {
        $link.remove();
      }
    }
    return false;
  });
});

 

       其中,出现错误的就在:

      $.get(url, function(data) {
        $('#gallery').append(data);
      });

    因为,我请求的是一个html的页面片段,将得到的html片段加载在index页面中,而jQuery.get()方法中漏写了dataType。

    在jQuery中的官网中,datatype默认为:智能匹配。即,由电脑智能猜测你的datatype是什么类型的,很显然,本次没有猜对。

   

    【解决方法】:很简单,将datatype写上。

 

      $.get(url, function(data) {
        $('#gallery').append(data);
      },'html');

 

     

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics