未捕获TypeError:无法读取未定义的属性“ownerDocument” [英] Uncaught TypeError: Cannot read property 'ownerDocument' of undefined

查看:5938
本文介绍了未捕获TypeError:无法读取未定义的属性“ownerDocument”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在教自己的AJAX AJAXify我的网站。在我的模板中,我有以下JS代码从视图中获取一些JSON数据,然后将数据附加到div。

 函数过滤器(类型){
$ .getJSON(
'/ activity_stream / global-activity-stream /',
{xhr:true,filter:type},
function(data){
$('。mainContent')。children()。remove();
$(data).appendTo('。mainContent');
});
}

$(。btn)。click(function(){
filter(recent);
});
}

我认为我的观点是返回正确的JSON,但现在数据没有被添加到 .mainContent div。



它提供了这个错误:


未捕获TypeError:无法读取属性ownerDocument '未定义



解决方案

确保您将选择器传递给jQuery,而不是某种形式的数据:

  $('.my-selector')

不是:

  $(['my-data'])


I'm teaching myself AJAX to AJAXify my site. In my template, I have the following JS code to get some JSON data from a view then append the data to a div.

function filter(type) {
  $.getJSON(
    '/activity_stream/global-activity-stream/', 
    {xhr: "true", filter: type}, 
    function(data) {
      $('.mainContent').children().remove();
      $(data).appendTo('.mainContent');
    });
  }

  $(".btn").click(function () { 
    filter("recent"); 
  });
}

I think my view is returning proper JSON but now data is not being added to the .mainContent div.

It gives this error:

Uncaught TypeError: Cannot read property 'ownerDocument' of undefined.

解决方案

Make sure you're passing a selector to jQuery, not some form of data:

$( '.my-selector' )

not:

$( [ 'my-data' ] )

这篇关于未捕获TypeError:无法读取未定义的属性“ownerDocument”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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