我在这里需要你的帮助。每次我尝试显示一个内容时,它都会显示几次(通常是 4 次),但应该只显示一次。我不知道我的代码有什么问题。如下:
$.ajax({
url: 'https://' + subParam + '.domain.name/' + akey + '/get_article',
async: false,
callback: 'callback',
crossDomain: true,
contentType: 'application/json; charset=utf-8',
type: 'POST',
dataType: 'jsonp',
success: function (data, status) {
if (data !== undefined && data.post !== undefined) {
if (data !== undefined && data.post.author.description > 0) {
if (data.post.thumbnail_images.large.url !== undefined) {
$.each(data.post.thumbnail_images, function (i2, type) {
$('#news').append('<div id="nimg" style="background-image: url(' + data.post.thumbnail_images.large.url + ')"></div><a href="author.html?type=authors&id=' + data.post.author.description + '"><div id="circletag" style="background-image: url(' + data.post.author.nickname + ')"></div></a><div id="newstext"><div id="newstitle">' + data.post.title + '</div><div>' + data.post.content + '</div><div><a href="#" onclick="window.open(\'' + data.post.custom_fields.syndication_permalink + '#comments\', \'_system\', \'location=yes\');" id="verstovcomments"></a></div></div>');
});
} else {
$('#news').append('<div id="nimg" style="background-image: url(' + defaultNews + ')"></div><a href="author.html?type=authors&id=' + data.post.author.description + '"><div id="circletag" style="background-image: url(' + data.post.author.nickname + ')"></div></a><div id="newstext"><div id="newstitle">' + data.post.title + '</div><div>' + data.post.content + '</div><div><a href="#" onclick="window.open(\'' + data.post.custom_fields.syndication_permalink + '#comments\', \'_system\', \'location=yes\');" id="verstovcomments"></a></div></div>');
}
}
}
}
});
……
我的 json 响应看起来像:
{
"status": "ok",
"post": {
"id": 3211,
"title": "title",
"content": "content"
"thumbnail": "/uploads\/2013\/09\/matkapital-150x150.jpg",
"thumbnail_size": "thumbnail",
"thumbnail_images": {
"full": {
"url": "/uploads\/2013\/09\/matkapital.jpg",
"width": 640,
"height": 427
},
"thumbnail": {
"url": "/uploads\/2013\/09\/matkapital-150x150.jpg",
"width": 150,
"height": 150
},
"medium": {
"url": "/uploads\/2013\/09\/matkapital-250x166.jpg",
"width": 250,
"height": 166
},
"large": {
"url": "/uploads\/2013\/09\/matkapital-640x426.jpg",
"width": 640,
"height": 426
}
}
}
}
是因为我正在使用$.each
还是有其他问题?