feed XML di aggiornamento sul click (jQTouch)
-
26-09-2019 - |
Domanda
Recentemente ho creato un feed XML -> HTML JavaScript funzione per un app iPhone sto sviluppando in jQTouch. originale Tutorial e Codice.
Mi chiedevo se qualcuno saprebbe un modo semplice e veloce per aggiornare i dati XML (afferrare di nuovo il feed) quando un link viene cliccato.
ad es. nel codice:
<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>
nella 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>
});
Molte grazie in anticipo per il vostro aiuto!
Soluzione
Verifica questo:
funzione Move getDataFeed () {..} al di fuori de la funzione e la cattura click pronto evento dal collegamento. 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();
});
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow