我正在使用 jQuery 1.9.1 并尝试进行 ajax 查询,该查询每 5 秒调用一次并更新一些内容。
使用下面的代码,我在 Chrome 控制台中收到以下错误:
Uncaught TypeError: Object #<Object> has no method 'apply'
错误所在的行是 jquery.min.js 的第 3 行
$(document).ready(function(){
function getData()
{
$.getJSON('/ajax/pull', function(data){
console.log(data.items);
$("span").each(data.items, function(items){
console.log(items);
if($(this).attr('id') in items)
{
console.log('here');
}
});
});
}
window.setInterval(function() { getData(); } , 5000);
});
我已经查看了具有相同问题的其他问题,但尝试这些修复对我的问题没有影响。
最佳答案
.each()仅接受 1 个参数,该参数是函数而不是数组。
关于javascript - jQuery:未捕获类型错误:对象#<Object>没有方法 'apply',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15316949/