سؤال

لقد قمت مؤخرًا بإنشاء وظيفة XML Teed -> HTML JavaScript لتطبيق iPhone الذي أقوم بتطويره في JQTouch. أصلي البرنامج التعليمي والرمز.

كنت أتساءل عما إذا كان شخص ما سيعرف طريقة سريعة وسهلة لتحديث بيانات 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 () {..} خارج دالة Ready و Capture Click Click من Link. تعيين معرف = "تغذية" في <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();

});
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top