2011-04-28 59 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