我正在使用RSS Feed和WinJS为Windows 8创建9GAG阅读器应用程序。
码:
function downloadBlogFeed() {
WinJS.xhr({ url: "http://feeds.feedburner.com/9GAG" }).then(function (rss) {
var items = rss.responseXML.querySelectorAll("item");
for (var n = 0; n < items.length; n++) {
var article = {};
article.title = items[n].querySelector("title").textContent;
var thumbs = items[n].querySelectorAll("thumbnail");
if (thumbs.length > 1) {
article.thumbnail = thumbs[1].attributes.getNamedItem("url").textContent;
article.content = items[n].textContent;
articlesList.push(article);
}
}
});
}
问题是我无法从FeedBurner获得9GAG Feed。我收到此错误:
Can't load http://feeds.feedburner.com/~d/styles/itemcontent.css. An app can’t load remote web content in the local context.
我也尝试过改变
WinJS.xhr({ url: "http://feeds.feedburner.com/9GAG" })
与
WinJS.xhr({ url: "http://9gag.com/?feed=rss" })
但我得到这个错误:
Exception is about to be caught by JavaScript library code at line 50, column 13 in ms-appx://7df7a30e-2f19-4f36-b368-c456fde8aabd/js/default.js
0x800a138f - JavaScript runtime error: Unable to get property 'querySelectorAll' of undefined or null reference
File: default.js
它指向这一行:
var items = rss.responseXML.querySelectorAll("item");
您能帮我,做对吗?
谢谢 !
最佳答案
干得好:
不幸的是,有一些黑客手段来获取图像,但可惜它起作用了,例如使用第三方RSS供稿的生活。
WinJS.xhr({ url: "http://feeds.feedburner.com/9GAG", responseType: 'responseXML' }).then(function (rss) {
var items = rss.responseXML.querySelectorAll("item");
for (var n = 0; n < items.length; n++) {
var article = {};
article.title = items[n].querySelector("title").textContent;
var imageStart = items[n].textContent.indexOf('<img src="') + 11;
var imageEnd = items[n].textContent.indexOf('"', imageStart);
article.thumbnail = items[n].textContent.substring(imageStart, imageEnd);
article.content = items[n].textContent;
articlesList.push(article);
}
});