flux XML Actualiser le clic (jQTouch)
-
26-09-2019 - |
Question
J'ai récemment créé un flux xml -> javascript html fonction pour une application iPhone que je développe dans jQTouch. originale Tutoriel et code.
Je me demandais si quelqu'un connaîtrait un moyen rapide et facile à actualiser les données xml (saisir à nouveau l'alimentation) lorsqu'un lien est cliqué.
par exemple. dans le 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>
dans le 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>
});
Un grand merci à l'avance pour votre aide!
La solution
Test ceci:
Déplacer la fonction getDataFeed () {..} en dehors de la fonction et prête événement clic de capture de lien. set id = "feed" dans <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();
});
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow