views:

31

answers:

1

Hi there,

I recently created an xml feed -> html javascript function for an iPhone app I'm developing in jQTouch. Original Tutorial & Code: http://bit.ly/cnNMKu

I was wondering if someone would know a quick and easy way to refresh the xml data (grab the feed again) when a link is clicked.

eg. in the code:

<div id="btns">
 <ul>
  <li><a href="#feed">Go to feed</a></li> <!-- When i click this, I want the getDataFeed function to dump the data & rerun. -->
</div>
<div id="feed">
 <div id="content_from_feed_inserted_here"></div>
</div>

in the javascript:

$(document).ready(function() {

function getDataFeed() {

    $('.loadingPic').show(); // show progress bar

    $.get('http://xxxxxxx.com/information.xml', function(d) {

    $(d).find('location').each(function(){

        var $location = $(this); 
        var the_data = $location.find('xml_data').text();

        var collected_data = collected_data += '<span>' + the_data + '</span>' ;
        $('#content_from_feed_inserted_here').empty().append($(collected_data)); // empty div first

        $('.loadingPic').fadeOut(1400); // remove progress bar
    });

}

// run on page load
getDataFeed();

// how do i also get it running when i click <li><a href="#feed">Go to feed</a></li>

});

Many thanks in advance for your help!

+1  A: 

Test this: Move function getDataFeed() {..} outside de ready function and capture click event from link. set id="feed" in <a>.

function getDataFeed() {

    $('.loadingPic').show(); // show progress bar

    $.get('http://xxxxxxx.com/information.xml', function(d) {

    $(d).find('location').each(function(){

        var $location = $(this); 
        var the_data = $location.find('xml_data').text();

        var collected_data = collected_data += '<span>' + the_data + '</span>' ;
        $('#content_from_feed_inserted_here').empty().append($(collected_data)); // empty div first

        $('.loadingPic').fadeOut(1400); // remove progress bar
    });
}

$(document).ready(function() {

    // how do i also get it running when i click <li><a href="#feed" id="#feed">Go to feed</a></li>
    $('#feed').click(getDataFeed);

    // run on page load
    getDataFeed();

});
angelcervera
jqtouch is obsolete. Use http://sencha.com or http://jquerymobile.com/
angelcervera
Hey thanks for the code, the button still doesn't seem to function. Any other ideas?
Nelga
Nelga
Remember add id in anchor tag. Test with firebug console opened. Any errors are showed?
angelcervera
Respect sencha and jquerymobile, you are right. But last beto of jqtouch is dated in October 2009. One year for a beta is a lot of time. In other hand, jqtouch is now part of "Sencha Lab", so is logic that jqtouch is not supported, no?
angelcervera
Actually, fixed! Using code as above, but instead of $('#feed').click(getDataFeed()); i added onClick="getUV()" to the <a href="#feed"> link
Nelga
Would rather use the id method as you have above, so i'll test this out a little, and if deadline looms, go with the onclick. :) Thanks for your help
Nelga
@Nelga Great, Thanks? Don't mention it. ;)
angelcervera
Ah! Fixed. Just needed to remove the extra set of brackets... This worked: $("#feed").click(getDataFeed);
Nelga