0
我目前正在開發一個應用程序來檢索來自WordPress的網站的訂閱源,並以jquery移動列表格式列出各個帖子。下面是JS代碼:所有動態帖子默認爲第一個對象
$(document).ready(function() {
var url = 'http://howtodeployit.com/category/daily-devotion/feed/';
$.ajax({
type: "GET",
url: document.location.protocol + '//ajax.googleapis.com/ajax/services/feed/load?v=1.0&output=json_xml&num=1000&callback=?&q=' + encodeURIComponent(url),
dataType: 'json',
error: function() {
alert('Unable to load feed, Incorrect path or invalid feed');
},
success: function (data) {
var postlist = data.responseData.feed.entries;
var html = '<ul data-role="listview" data-filter="true">';
for (var i = 0; i < 6; i++) {
var entry = postlist[i];
console.log(entry);
html += '<li>';
html += '<a href="#articlepost" onclick="showPost(' + entry.id + ')">';
html += '<div class="etitle">' + entry.title + '</div>';
html += '<div class="esnippet">' + entry.contentSnippet + '</div>';
html += '</a>';
html += '</li>';
}
html += '</ul>';
$("#devotionlist").append(html);
$("#devotionlist ul[data-role=listview]").listview();
}
});
});
function showPost(id) {
$('#articlecontent').html("Loading post...");
$.getJSON('http://howtodeployit.com/category/daily-devotion/?json=get_post&post_id=' + id + '&callback=?', function (data) {
var html = '';
html += '<h3>' + data.post.title + '</h3>';
html += data.post.content;
$('#articlecontent').html(html);
});
}
當我點擊任何顯示的6個員額中,只有第一篇文章的內容被顯示,而不是個別職位的內容。
您確認服務器正在返回一個不同的帖子?你有沒有證實你沒有通過每個鏈接相同的ID? – Gregg
將XML提要轉換爲JSON時,它看起來像Google API,但不包含帖子ID。希望使用谷歌的'google.feeds.Feed.MIXED_FORMAT'來獲得額外的XML屬性,所以我可以得到元素並從中提取帖子ID,但沒有工作 –
Chelseawillrecover
我終於解決了這個問題,我有已經發布在另一篇文章中。我也會在這裏發佈給其他人看 – Chelseawillrecover