Minimaalne ajaxi näide

Allikas: Lambda
<html>
<head>
<script>
var request;
  
function myupdatefun() {
  var response; 
  alert("myupdatefun called with"+request.readyState)
  if (request.readyState == 4) {   
       alert("Server is done, request.readyState == 4!"); 
       if (request.status == 200) {
          alert("Server sent data ok,request.status == 200!");       
          response = request.responseText
          alert("response is: "+response)
          document.getElementById('sisu2').innerHTML=response;          
       } else if (request.status == 404)
         alert("Request URL does not exist");
       else
         alert("Error: status code is " + request.status);   
  }       
}  

function ajaxcall() {
  var url;
  request = new XMLHttpRequest();  
  url = "http://dijkstra.cs.ttu.ee/~tammet/cgi-bin/otsi.py?salvestaja=tanel&table=t1"  
  request.open("GET", url, true);
  request.onreadystatechange = myupdatefun;
  request.send(null);
}  


</script>
<body>
Tere kah!
<form>
<input type="button" value="Proovi!" onclick="ajaxcall()">
</form>

<div id="sisu2"></div>
</body>