Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Phonegap RSS feeds, Javascript

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?

like image 963
Dhaivat Pandya Avatar asked Jul 23 '26 19:07

Dhaivat Pandya


2 Answers

I recently made one using this tutorial : http://net.tutsplus.com/tutorials/javascript-ajax/how-to-build-an-rss-reader-with-jquery-mobile-2/

like image 168
Jivings Avatar answered Jul 25 '26 09:07

Jivings


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

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

<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.js I use the following:

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.

like image 44
Lasse Christiansen Avatar answered Jul 25 '26 09:07

Lasse Christiansen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!