0

从昨晚开始,我一直在尝试使用 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>

我尝试了很多代码,最终使用了这个问题Parse RSS with jQuery中回答的代码

这是我的代码

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>
4

1 回答 1

1

在其中放置一个断点并逐步执行代码。如果您的警报未显示,则意味着 1) $.get 请求失败,因此您的“成功”函数将永远不会被调用,或者 2) 您的成功函数被调用但它没有收到警报,因为其中一个findtext调用引发异常。

于 2012-07-06T02:51:28.743 回答