2010-10-27 61 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