从昨晚开始,我一直在尝试使用jQueryMobile使atom feed工作,但没有运气。我正在本地处理代码。
我正在使用jQueryMobile网站中提供的脚本
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.css" />
<script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
<script src="http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.js"></script>
我尝试了很多代码,最终使用了这个问题中回答的代码 使用 jQuery 解析 RSS
这是我的代码
function refreshFeed2() {
$.get("resp2.xml", function (data) {
var $xml = $(data);
$xml.find("item").each(function () {
var $this = $(this),
item = {
title: $this.find("title").text(),
link: $this.find("link").text(),
description: $this.find("description").text(),
pubDate: $this.find("pubDate").text(),
author: $this.find("author").text()
}
alert(item.title);
});
});
}
最后,我尝试弹出警报,但它没有显示任何内容。
代码中有什么问题?
---更新---我正在使用移动设备---更新---
为了调试。这是一个更新的代码
function refreshFeed2() {
alert("start call");
$.get("resp.xml", function (data) {
alert("start parse");
var $xml = $(data);
alert("set data");
$xml.find("item").each(function () {
var $this = $(this),
item = {
title: $this.find("title").text(),
link: $this.find("link").text(),
description: $this.find("description").text(),
pubDate: $this.find("pubDate").text(),
author: $this.find("author").text()
}
alert(item.title);
});
});
alert("end call");
}
所以我添加了警报..那里的问题它仅在"开始呼叫"和"结束呼叫"中弹出。
我的示例 xml 看起来像这样。但这实际上要长得多
<rss version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
xmlns:slash="http://purl.org/rss/1.0/modules/slash/">
<channel>
<title>title of the feed</title>
<atom:link href="http://www.mainlink.com/livefeed" rel="self" />
<link>http://www.mainlink.com/</link>
<description>
</description>
<language>en-us</language>
<pubDate>Fri, 06 Jul 2012 04:47:51 +0800</pubDate>
<lastBuildDate>Fri, 06 Jul 2012 04:47:51 +0800</lastBuildDate>
<item>
<title>title1</title>
<link>http://www.link1.com/</link>
<description>desc1</description>
<pubDate>Fri, 06 Jul 2012 04:47:09 +0800</pubDate>
<guid>25542832</guid>
</item>
<item>
<title>title2</title>
<link>http://www.link1.com/</link>
<description>desc2</description>
<pubDate>Fri, 06 Jul 2012 04:47:09 +0800</pubDate>
<guid>25542831</guid>
</item>
</channel>
</rss>
在其中放置一个断点并单步执行代码。如果警报未显示,则表示 1) $.get 请求失败,因此永远不会调用"成功"函数,或 2) 成功函数被调用,但由于其中一个find
或text
调用引发异常,它不会到达警报。