为什么这个ajax调用在IE中不起作用?

时间:2012-08-30 13:57:05

标签: ajax internet-explorer

适用于Chrome,FF,Safari等。

JSON响应似乎很好......我猜这与我正在做或不在我的代码中做的事情有关:

var getPhotos = function() {
  $.ajax({
    url: 'https://api.parse.com/1/classes/Photo',
    headers: {
      'X-Parse-Application-Id': config.parseAppId,
      'X-Parse-REST-API-Key': config.parseRestKey
    },
    type: 'GET',
    dataType: 'json',
    data: {
      'where': '{"event": "' + <%= @event.id %> + '"}',
      'order': '-createdAt',
      'limit': '12'
    },
    success: function (data) {
      $('#community-gallery').children().remove();
      data.results.forEach(function (photo) {
        $('#community-gallery').append($('<a href="'+photo.file.url+'" rel="gallery"><img src="'+photo.file.url+'" width="130" style="padding: 0px 15px 15px 0;" /></a>'));
      })
    },
    error: function () {
      alert('Problem reading photos');
    }
  });
};

3 个答案:

答案 0 :(得分:0)

您在forEach中使用的数组data.results.forEach方法仅在IE9 +中受支持,请参阅底部的兼容性表:

https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Array/forEach

答案 1 :(得分:0)

此外,您在$电话中使用append()时,它应该只是html内容。

答案 2 :(得分:0)

缓存:false, 从我的经验来看,IE在IE中也非常重要