我最近为我在jQTouch中开发的iPhone应用程序创建了xml feed-> html javascript函数。 Original教程和代码。
我想知道是否有人会在单击链接时知道一种快速简便的方法来刷新xml数据(再次获取提要)。
例如。
在代码中:
<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>
});
在此先感谢您的帮助!
最佳答案
测试一下:
将函数getDataFeed(){..}移至就绪函数之外,并捕获链接中的click事件。在<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();
});
关于javascript - 单击时刷新XML提要(jQTouch),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4030232/