title: jQuery/AJAX call with a timer
body: <p>How can i implement the below code with jQuery/AJAX timer,(I have created 2 URL classes by using web.py.Here 1st URL will return a random number between 1 and 250.I have created an AJAX call in the 2nd URL,so that when you hit the button ,AJAX will call the values from the 1st URL and it will display inside the text box),Now i just want to modify the code like during every 5 seconds AJAX should call the numbers from 1st URL and it should display inside the text box.Is there any way to solve this problem by using jQuery/AJAX timer.</p>
  
  <pre><code>import web
  import random
  
  urls = (
    '/', 'main',
    '/random','fill')
  
  
  app = web.application(urls, globals(), True)
  
  class main:
      def GET(self):
         return  random.randint(1,250)
  
  
  class fill:
      def GET(self):
          return'''
          &lt;html&gt;
          &lt;head&gt;
          &lt;script type="text/javascript" src="http://ajax.microsoft.com/ajax/jquery/jquery-1.4.2.min.js"&gt;&lt;/script&gt;
          &lt;script type="text/javascript"&gt;
          $(document).ready(function(){
          $("button").click(function(){
            $.ajax({url:"http://127.0.0.1:8080/", success:function(result){
               $("#text").val(result);
            }});
          });});
          &lt;/script&gt;
          &lt;/head&gt;
          &lt;body&gt;
  
  
          &lt;form&gt;
          &lt;input type = "text" id = "text"/&gt;
          &lt;/form&gt;
          &lt;h2&gt;Hit the button to view random numbers&lt;/h2&gt;
          &lt;button&gt;Click&lt;/button&gt;
          &lt;/body&gt;
          &lt;/html&gt;'''
  
  
  
  if __name__ == "__main__":
      app.run()
  </code></pre>