admin管理员组

文章数量:1390564

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
});

本文标签: javascriptSCRIPT438 Object doesn39t support property or method 39forEach39Stack Overflow