title: Refresh JS script value every second
body: <p>I have a script which is a getting value "average" from JSON array</p>
  
  <pre><code>&lt;p id="ticker"&gt;&lt;/p&gt;
  
  
  &lt;script&gt;
    var xmlhttp = new XMLHttpRequest();
    xmlhttp.onreadystatechange = function () {
    myObj = JSON.parse(this.responseText);
    document.getElementById("ticker").innerHTML = myObj.average; };
    xmlhttp.open("GET", "https://bitbay.net/API/Public/BTC/ticker.json", true);
    xmlhttp.send();
  &lt;/script&gt;
  </code></pre>
  
  <p>My problem is making this <code>&lt;p&gt;</code> refresh every some seconds. I wasted all day to do this. Could you please help me with it?</p>