2010-10-27 69 views
1

我最近为jQTouch开发的iPhone应用程序创建了一个xml feed - > html javascript函数。 Original教程&代码。点击刷新XML feed(jQTouch)

我想知道是否有人会知道一个快速简单的方法来刷新xml数据(抓住feed再次),当一个链接被点击。

例如。 代码:

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

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

}); 

提前感谢您的帮助!

回答

2

测试此项: 移动函数getDataFeed(){..}在准备就绪函数之外并从链接捕获单击事件。在<a>中设置id =“feed”。

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(); 

}); 
+0

jqtouch已过时。使用http://sencha.com或http://jquerymobile.com/ – angelcervera 2010-10-27 05:44:18

+0

嘿感谢代码,按钮仍然似乎不起作用。任何其他想法? – Nelga 2010-10-27 05:53:16

+0

- 在jqtouch上 - 不一定是这样,它在github上非常活跃,再加上那需要重写应用程序。另外不幸的是,jquery mobile仍然只有alpha版本,并且没有静态标签栏/标题,而sencha完全不同 - 面向对象的js。 – Nelga 2010-10-27 05:54:39