Phonegap RSS 提要,Javascript

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6483804/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-25 20:50:37  来源:igfitidea点击:

Phonegap RSS feeds, Javascript

javascriptjqueryhtmlcordova

提问by Dhaivat Pandya

I need to write a PhoneGap application (with HTML5 and JS, I don't need compatibility with IE) with AJAX so that it reads an RSS feed and looks up some specific information from it. The problem I'm having is that I have I don't the best way to do an RSS feed, and jQuery can't do XML. Any suggestions?

我需要使用 AJAX 编写 PhoneGap 应用程序(使用 HTML5 和 JS,我不需要与 IE 兼容),以便它读取 RSS 提要并从中查找一些特定信息。我遇到的问题是我不是做 RSS 提要的最佳方式,而 jQuery 不能做 XML。有什么建议?

回答by Lasse Christiansen

I have just made a phonegap application that parses an external RSS feed using jFeed. I'll give you an example:

我刚刚制作了一个使用 jFeed 解析外部 RSS 提要的 phonegap 应用程序。我给你举个例子:

First, I include the following Java scripts in my index.html file:

首先,我在 index.html 文件中包含以下 Java 脚本:

<head>
    ...
    <script type="text/javascript" src="phonegap-1.0.0.js"></script>
    <script type="text/javascript" src="jquery/jquery-1.6.4.js"></script>
    <script type="text/javascript" src="jquery.mobile/jquery.mobile-1.0b3.min.js"></script>
    <script type="text/javascript" src="jquery.jfeed/dist/jquery.jfeed.js"></script>
    <script type="text/javascript" src="scripts/my.js"></script>
    ...
</head>

Then, in my.jsI use the following:

然后,在my.js我使用以下内容:

parseFeed();

function parseFeed() {
$.getFeed({
    url: 'http://someUrl.com',
    dataType: "xml",
    success: function(feed) {

    $('#feedresult').empty();

    var html = '<ul data-role="listview">';

    for(var i = 0; i < feed.items.length; i++) {

        var item = feed.items[i];

        html += '<li>'
        + '<a href="#article?id='
        + i
        + '">'
        + item.title
        + '</a>'
        + '</li>';
    }

    html = html + '</ul>';

    $('#feedresult').append(html);
    $('#main').page('destroy').page();

    }});
};

The code then creates a listview (jQuery mobile) in my #feedresult div where each entry represents a feed item. As phonegap utilizes some sort of web view that loads all content using the file:/// protocol ( http://groups.google.com/group/phonegap/browse_thread/thread/b60bda03bac6e9eb), there is no issue in doing cross domain XMLHttpRequest from phonegap.

然后代码在我的#feedresult div 中创建一个列表视图(jQuery mobile),其中每个条目代表一个提要项目。由于 phonegap 利用某种网络视图,使用 file:/// 协议(http://groups.google.com/group/phonegap/browse_thread/thread/b60bda03bac6e9eb)加载所有内容,因此跨域没有问题来自 phonegap 的 XMLHttpRequest。

回答by Mike Castro Demaria

This question is old, but can be helpful to solve it in 2014 ;-).

这个问题很老了,但有助于在 2014 年解决它;-)。

I test many jQuery plugin to include a RSS reader, but the only this work like a charme in 1mn is zrssfeed

我测试了许多 jQuery 插件以包含 RSS 阅读器,但唯一像 1mn 中的魅力一样的工作是zrssfeed

Just add the call (after call jquery and jquery mobile) in the header:

只需在标题中添加调用(在调用 jquery 和 jquery mobile 之后):

<script type="text/javascript" src="jquery.zrssfeed.min.js"></script>

And after start th jquery call like this :

在像这样开始 jquery 调用之后:

<script type="text/javascript">
    $(document).ready(function () {
        $('#feedresult').rssfeed('http://my.wordpress.website.com/feed/', {
            limit: 5
        });
    });
</script>

I hope this help, Mike

我希望这会有所帮助,迈克

回答by petraszd

What You mean jQuery can't do XML. jQuery is JavaScript and jQuery uses XMLHttpRequestwhile doing Ajax calls. See the name XML*. See: http://api.jquery.com/jQuery.ajax/. There is dataTypeparam. You can pass xmlto it. After that You will get dom object with all dom object methods.

你的意思是 jQuery 不能做 XML。jQuery 是 JavaScript,jQueryXMLHttpRequest在执行 Ajax 调用时使用。见名字XML*。请参阅:http: //api.jquery.com/jQuery.ajax/。有dataType参数。你可以传给xml它。之后,您将获得具有所有 dom 对象方法的 dom 对象。

You can event use it as second param to jQuery's selectors:

您可以将其用作 jQuery 选择器的第二个参数:

jQuery.get(url, {}, function (data) {
    var entries = $("entry", data);
    doSomething(entries);
}, 'xml');

回答by sparkymat

One option would be to use a RSS-to-JSON pipe, like this one here: http://pipes.yahoo.com/pipes/pipe.info?_id=2FV68p9G3BGVbc7IdLq02Q

一种选择是使用 RSS-to-JSON 管道,就像这里的这个:http: //pipes.yahoo.com/pipes/pipe.info?_id=2FV68p9G3BGVbc7IdLq02Q