SCRIPT438:对象不支持属性或方法'forEach'

4

IE8不支持属性或方法'forEach'

$('.tabs').tabs();
$('#search-consumables [data-ajax-call]').change(function() {

    var $this = $(this),
        settings = $this.data(),
        $target = $(settings.target);

    $.ajax({
       type: 'GET',
       url: 'index.php?route=module/quicklookup/' + settings.ajaxCall,
       data: $this.closest('form').serializeArray(),
       dataType: 'json',
       success: function(data) {
           var html = '';
           $target.find(':not(.blank)').remove();
           html = $target.html();
           data.forEach(function(entry) {
               html += '<option value="'+entry.id+'">'+entry.name+'</option>';
           });
           $target.html(html);
        }
    });
});

我已经尝试过

$.each(data, function(entry) { 

然而数据返回undefined,我错过了什么使它在IE8中运行?


data 的类型为 object,没有 forEach() 方法。 - jmoerdyk
1个回答

6
jQuery.each回调函数的第一个参数是数组中值的索引;第二个参数是实际的值。
尝试使用:
$.each(data, function(i, entry) {
    // your code here
});

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接