2016-11-13 54 views
0

我在春天和一般webdev新手。我正在春季開機寫小應用程序,在那裏我顯示真正的weatherstatus。數據在JpaRepository和HSQLDB的幫助下存儲。我可以使用Spring Boot和JSP強制更新內容/頁面嗎?

每分鐘我都會收集數據,解析並將其添加到存儲庫。邏輯完成了。

如何強制客戶端的瀏覽器刷新,當我得到新的實際數據?

+0

可能有用:https://en.wikipedia.org/wiki/Push_technology#Long_polling –

+0

一個更復雜的方法將包括的WebSockets:http://stackoverflow.com/questions/10028770/in-what -situations-將-Ajax的長 - 短 - 輪詢待優選的環比HTML5的websock。我已經在我們的項目中使用了大約一年,雖然有一個學習曲線,但它相當好。 – bphilipnyc

回答

0

如果你正在使用REST的電話,那麼這對你來說會很容易。

<script> 
    $(document).ready(function(){ 
     setInterval(getWeather(),2000); 
     //Here get weather is a method and 2000 is numbers of milliseconds after which you want to update weather data 
    }); 

    function getWeather(){ 
     $.ajax({ 
      type : 'GET' 
      url : 'Your url here' 
      success : function(data){ 
       //set received data to your container 
      } 
     }); 
    } 
</script> 
相關問題