2013-11-22 30 views
0

我想每10秒更新一次json數據。 使用此功能會使腳本崩潰。 有沒有更好的方法?使用refreshInterval更新JSON

$(function refreshUsers() { 
    $.getJSON('/api/TrainlocationList/', function (loadscale) { 
     $(loadscale).each(function (i, item) { 
      $(item).each(function (i, Type) { 
       $('#LabelID').html(Type.TrainLocationName); 
       var refreshInterval = setInterval(refreshUsers, 10 * 1000); 
      }); 
     }); 
    }); 
}); 

回答

0

嘗試......

setInterval(function() { 
    $.getJSON('/api/TrainlocationList/', function (loadscale) { 
     $(loadscale).each(function (i, item) { 
      $(item).each(function (i, Type) { 
       $('#LabelID').html(Type.TrainLocationName); 
      }); 
     }); 
    }); 
}, 10000) 
+0

看起來不錯!它每秒運行一次。幾個小時後裝載一個新的角色?與第一個例子我的瀏覽器在10分鐘後崩潰:( – user2385302

+0

我已經更新到現在每10秒鐘,你可以留意使用鉻工具,或者看看使用'SignalR'? – christiandev

+0

@ user2385302,如果這工作,你可以積極幫助其他人解決同樣的問題。 – christiandev