0

I am newbie at spring and generally webdev. I am writing small application in spring boot, where on hompage I display actual weatherstatus. Data is storage with help of JpaRepository and HSQLDB.

Each minute I recive data, parse, and add it to repository. The logic is done.

How to force client's browser to refresh, when I get new, actual Data?

Michael Petch
  • 46,082
  • 8
  • 107
  • 198
Konrad Dziurdź
  • 717
  • 3
  • 8
  • 15
  • May be useful: https://en.wikipedia.org/wiki/Push_technology#Long_polling – Rudziankoŭ Nov 13 '16 at 15:57
  • A more involved approach would be including websockets: http://stackoverflow.com/questions/10028770/in-what-situations-would-ajax-long-short-polling-be-preferred-over-html5-websock. I've been using it in our project for about a year now and while there's a learning curve, it's fairly good. – riddle_me_this Nov 13 '16 at 18:28

2 Answers2

0

With HTML:

To add this kind of feature without using any Ajax feature, you can use the following meta:

<meta http-equiv="refresh" content="0;URL='http://thetudors.example.com/'" /> 

With Javascript:

If you can add Javascript in the project, my advice is to create a endpoint to check periodically with JQuery or Fetch:

Juan Antonio

jabrena
  • 1,166
  • 3
  • 11
  • 25
0

If you are using REST calls then it will be very easy for you.

<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>
Shalin Patel
  • 1,079
  • 1
  • 10
  • 15