2010-03-20 39 views

回答

2

當然...

... 
success: function(data){ 
    $.ajax({..... 
} 
.... 

和之前說過,你的範圍被封閉捕獲。

1

你應該可以做到這一點。封閉使一切都保持在範圍之內。

1

除了Matthew's answer,您還可以使用setTimeout()重複AJAX調用在預定的時間間隔,如下面的例子:

function autoUpdate() { 

    $.ajax({ 
     type: 'GET', 
     url: '/web-service/?no_cache=' + (new Date()).getTime(), 

     success: function(msg) { 
     // Add your logic here for a successful AJAX response. 
     // ... 
     // ... 

     // Relaunch the autoUpdate() function in 5 seconds 
     setTimeout(autoUpdate, 5000); 
     } 
    }); 
}