$.ajax({
url: 'https://api.imgur.com/3/album/' + sharedAlbumID,
type: 'GET',
beforeSend: function(xhr){xhr.setRequestHeader('Authorization', 'Client-ID '+imgurClientID);},
success: function(resp) {
var dataLink = 'http://i.imgur.com/' + resp.data.cover + '.jpg';
var url = encodeURI(window.location.href);
var media = encodeURI(dataLink);
$('#pinterestHolder').html('<a target="_blank" data-pin-config="beside" href="//pinterest.com/pin/create/button/?url=' + url + '&media=' + media + '&description=Imagedoku album recommendation: ' + resp.data.id + '" data-pin-do="buttonPin" ><img src="//assets.pinterest.com/images/pidgets/pin_it_button.png" /></a>');
if (resp.data.images.length >= 9) {
for (var i = 0; i < 9; i++) {
var imgID = resp.data.images[i].id;
imgID += 't';
imgID = 'http://i.imgur.com/' + imgID + '.jpg';
$('#albumHolder').append('<div class="albumThumbHolder"><a href="' + resp.data.images[i].link + '" target="_blank"><img class="imguralbumthumb" title="' + resp.data.images[i].id + '" src="' + imgID + '" /></a></div>');
}
} else {
$('#insufficientImagesError').modal();
}
$('#albumLink').html('<a href="http://imgur.com/a/' + sharedAlbumID + '" target="_blank">View album on Imgur</a>');
},
error: function(resp) {
$('#imgurMalformedError').modal();
}
});
此代码在Chrome中按预期工作,但会返回
resp.data is undefined
上的错误
var dataLink = 'http://i.imgur.com/' + resp.data.cover + '.jpg';
这是Imgur API,我相信你可以告诉我。不知何故,问题是Firefox nto读取jQuery回调中发送的数据对象。我怎样才能解决这个问题?我只对在Webkit和Mozilla中完成这项工作感兴趣,而且它在Webkit中有效 - 任何hacky的答案都会没问题。
答案 0 :(得分:0)
问题是我没有指定接收dataType:'json',Chrome显然猜到了,但Firefox没有。