title: html send get() request to Flask server every second
body: <p>How can I make a html page send a get() request to a server every second, so the data is updated.I have tried to use angular js for the clock/timer part, but didn't succeed. When receiving a "GET" request, the server will return a random integer to the index.html page. Javascript part sends out a GET request to the server every second. However, I couldn't see the number updated per second as I excepted.  </p>
  
  <pre><code>from flask import Flask, render_template, request
  import numpy as np
  app = Flask(__name__)
  
  @app.route('/db', methods = ['Get'])
  def hello():
      return render_template('index.html', data = np.random.randint(1,10))
  
  if __name__ == '__main__':
      app.run()
  </code></pre>
  
  <p>index.html</p>
  
  <pre><code>&lt;html np-app='myApp'&gt;
      &lt;head&gt;
          &lt;script src="/Scripts/angular.min.js"&gt;&lt;/script&gt;
          &lt;script src="/Scripts/myController.js"&gt;&lt;/script&gt;
      &lt;/head&gt;
  
      &lt;body np-controller='myController'&gt;
          {{ data }}  
      &lt;/body&gt; 
  
  &lt;/html&gt;
  </code></pre>
  
  <p>myController.js</p>
  
  <pre><code>myApp = angular.module('myApp', []);
  
  myApp.controller('myController', function getStuff($http, $timeout) {
         $http.get().success(function() {
         $timeout(getStuff, 1000);
         });
  });
  </code></pre>
  
  <p>Update:
  I rewrote the myController.js file, based on inf1n1te's information. But I must have done something wrong and so it didn't work:</p>
  
  <pre><code>myApp = angular.module('myApp', []);
  
  myApp.controller('myController', ['$interval', '$http', function getStuff($http, $interval) {
         $interval($http.get().success(), 1000);       
         }]);
  </code></pre>