最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - SCRIPT438: Object doesn't support property or method 'forEach' - Stack Overflow

programmeradmin1浏览0评论

IE8 support property or method '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);
        }
    });
});

I have tried

$.each(data, function(entry) { 

yet data then returns undefined, What am I missing to get this working in IE8?

IE8 support property or method '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);
        }
    });
});

I have tried

$.each(data, function(entry) { 

yet data then returns undefined, What am I missing to get this working in IE8?

Share Improve this question asked Apr 5, 2013 at 21:23 user2250678user2250678 431 silver badge3 bronze badges 1
  • data is of the type object which has no method forEach() – jmoerdyk Commented Apr 5, 2013 at 21:29
Add a ment  | 

1 Answer 1

Reset to default 6

The first argument passed to the jQuery.each callback is the index of the value in the array; the second argument is the actual value.

Try using:

$.each(data, function(i, entry) {
    // your code here
});
发布评论

评论列表(0)

  1. 暂无评论