2011-04-28 41 views
2
jQuery(document).ready(function(){ 

    // ok im geting the value here maybe i should make it in one var or in a function 
    var feedid = $('.feeds .feed:first').attr('id'); 
    var feedid = feedid.match(/^feed-(\d+)$/); 

    if (feedid){ 
     setInterval(function() { 

      $.ajax({ 
       type: 'GET', 
       url: '/area51/ajax', 
       context: $("#ajax-information"), 
       data: { f: feedid[1] }, 
       success: function(data) { 

        $(this).html(data); 

        var feedstatus = $('.ajax-status').attr('id'); 
        if (feedstatus == 'none') { 
         $(this).hide();  
        }; 

        if (feedstatus == 'true') { 
         $(this).fadeIn().html(data); 
         $('#ajax-information a').click(function(e) { 
          $('.feeds').fadeIn().load('/ .feeds'); 
          $('#ajax-information').fadeOut(); 
          e.preventDefault(); 
         }); 
              // this is what im trying to do 
         feedid.load(); 
        }; 
       } 
      }); 
     }, 7000); 
    }; 
}); 

即時嘗試重新載入,所以我的feedid被刷新,有沒有辦法做到這一點?重新加載一個函數或var在jquery(新手)

編輯*

function getNewFeed(){ 
     var feedid = $('.feeds .feed:first').attr('id'); 
     var feedid = feedid.match(/^feed-(\d+)$/); 

     if (feedid){ 
     $.ajax({ 
      type: 'GET', 
      url: '/area51/ajax', 
      context: $("#ajax-information"), 
      data: { f: feedid[1] }, 
      success: function(data) { 

       $(this).html(data); 

       var feedstatus = $('.ajax-status').attr('id'); 
       if (feedstatus == 'none') { 
        $(this).hide();  
       }; 

       if (feedstatus == 'true') { 
        $(this).fadeIn().html(data); 
        $('#ajax-information a').click(function(e) { 
         //I commented the following line because (as i understand)  
         //getNewFeed() makes the ajax call 
         $('.feeds').fadeIn().load('/ .feeds'); 
         $('#ajax-information').fadeOut(); 
         e.preventDefault(); 
        }); 
       }; 
      } 
     }); 
    } 
} 

jQuery(document).ready(function(){ 
    setInterval(function() { 
     getNewFeed();    
    }, 7000);  
}); 

這一個偉大的工程!無論如何,如果有什麼辦法可以做到這一點,請發佈。

謝謝你在找!

亞當·拉馬丹

回答

1

如果你想每隔7秒後重新載入,或當按下鏈接(目前尚不清楚對你的class和id的),我認爲這應該是這樣:

function getNewFeed(){ 
     var feedid = $('.feeds .feed:first').attr('id'); 
     var feedid = feedid.match(/^feed-(\d+)$/); 

     if (feedid){ 
     $.ajax({ 
      type: 'GET', 
      url: '/area51/ajax', 
      context: $("#ajax-information"), 
      data: { f: feedid[1] }, 
      success: function(data) { 

       $(this).html(data); 

       var feedstatus = $('.ajax-status').attr('id'); 
       if (feedstatus == 'none') { 
        $(this).hide();  
       }; 

       if (feedstatus == 'true') { 
        $(this).fadeIn().html(data); 
        $('#ajax-information a').click(function(e) { 
         //I commented the following line because (as i understand)  
         //getNewFeed() makes the ajax call 
         //$('.feeds').fadeIn().load('/ .feeds'); 
         getNewFeed(); //We force to get new feed with click 
         $('#ajax-information').fadeOut(); 
         e.preventDefault(); 
        }); 
       }; 
      } 
     }); 
    } 
} 

jQuery(document).ready(function(){ 
    setInterval(function() { 
     getNewFeed();    
    }, 7000);  
}); 

希望這有助於

+0

工作偉大的,但我們不能只是刷新feedid?我的意思是使用這些功能?看到編輯:)反正謝謝!,它確實有效,但動畫不平滑。 – 2011-04-28 05:48:32

+0

如果你發佈你的html(只有重要的部分)才能看到它的結構,我將能夠幫助你做到這一點 – 2011-04-28 06:34:04