我正在自学 AJAX 以 AJAXify 我的网站。在我的模板中,我有以下 JS 代码从 View 中获取一些 JSON 数据,然后将数据附加到 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");
});
}
我认为我的 View 返回了正确的 JSON,但现在数据没有被添加到 .mainContent
div。
它给出了这个错误:
Uncaught TypeError: Cannot read property 'ownerDocument' of undefined.
最佳答案
确保您将选择器传递给 jQuery,而不是某种形式的数据:
$( '.my-selector' )
不是:
$( [ 'my-data' ] )
关于javascript - 未捕获的类型错误 : Cannot read property 'ownerDocument' of undefined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17594855/