Ajax, at an interval at w3schools

<!DOCTYPE html>
<html>
<body>

<p id="demo">Let AJAX change this text.</p>

<button type="button" onclick="on()">Change Content</button>


// http://www.w3schools.com/ajax/tryit.asp?filename=tryajax_asyncfalse

setInterval(function() { 
  var d = new Date().getSeconds();
  var xhttp = new XMLHttpRequest();

  xhttp.onreadystatechange = function() {
    if (xhttp.readyState == 4 && xhttp.status == 200) {
      document.getElementById("demo").innerHTML = xhttp.responseText + d.toString();
    }
  };
  xhttp.open("GET", "ajax_info.txt", true);
  xhttp.send();
}, 1000);//time in milliseconds 

function on() {
  var d = new Date().getSeconds();
  var xhttp = new XMLHttpRequest();

  xhttp.onreadystatechange = function() {
    if (xhttp.readyState == 4 && xhttp.status == 200) {
      document.getElementById("demo").innerHTML = xhttp.responseText + d.toString();
    }
  };
  xhttp.open("GET", "ajax_info.txt", true);
  xhttp.send();
};


</body>
</html>
Advertisements

~ by nambabwe on 2016/08/11.

 
%d bloggers like this: