2012-02-05 37 views
-1

請幫我先做這個jQuery的:類名多AJAX請求

我有這個div

<div class="loader" alt="stat.php"> 
     Here i want to load static 
</div> 

<div class="loader" alt="notify.php"> 
     Here i want to load notification 
</div> 

<div class="loader" alt="alert.php"> 
     Here i want to load new messages 
</div> 

,我想做到這一點

我想使這個的div這個類加載器=

負載每1分鐘,從它的ALT得到

意味着

1分鐘後我想打的foreach格

類= 「裝載機」

Ajax請求其ALT 頁面,裏面

平均每1分鐘,我想每格都是這樣的

<div class="loader" alt="stat.php"> 
     Static loaded from stat.php 
</div> 

<div class="loader" alt="notify.php"> 
     notification loaded from notify.php 
</div> 

<div class="loader" alt="alert.php"> 
     messages loaded from alert.php 
</div> 

ev請求1分鐘請求?

我怎樣才能做到這一點

回答

1

像這樣

function refreshDivs() { 
    $('.loader').each(function() { 
     $this = $(this); 
     $this.load($this.prop('alt')); // load in the URL using the alt attribute 
    } 
} 

setInterval(refreshDivs, 60000); // run every minute 

使用每個方法與類loader每個DOM元素處理然後它使用load()方法,以取代的內容元素與從URL加載的HTML。

Docs on load() heredocs on each() here

1
$('.loader').each(function() { 
    var url = $(this).attr('alt'); 
    var thisDiv = $(this); 
    window.setInterval(function() { 
     thisDiv.load(url); 
    }, 60000); 
});