2012-07-29 73 views
-1
前顯示的東西

我的問題是,我該怎麼讓jQuery的負載的setInterval前瞬間的一些信息,當是負載的setInterval將更新它。的setInterval jQuery的

<script type=\"text/javascript\"> 
    function getData(){ 
     $(\"#whereshow\").load(\"somefile.php\"); 
    } 
    setInterval(\"getData()\", 5000); 
</script> 

我可以做些什麼嗎?

<script type=\"text/javascript\"> 
    function getData1(){ 
     $(\"#whereshow\").load(\"somefile.php\"); 
    } 
    function getData(){ 
     $(\"#whereshow\").load(\"somefile.php\"); 
    } 
    setInterval(\"getData()\", 5000); 
</script> 

...和getData1()會顯示即時的onload頁信息,然後將停止,並setIntervall西港島線做其他更新作業?

回答

1

基本上你想要做的是有setInterval火立即以及在間隔。

這很容易。

(function() { 
    var getData = function() { 
     $("#whereshow").load("somefile.php"); 
    } 
    setInterval(getData,5000); 
    getData(); 
})(); 

請參閱,只是調用函數;)我還爲腳本添加了一些改進。


編輯:我只是想的做的另一種方式:

setInterval((function() { 
    $("#whereshow").load("somefile.php"); 
    return arguments.callee; 
})(),5000); 
+0

第二個解決方案是真正的聰明。不可讀,但仍然非常整齊。 – 2012-07-29 11:41:57