Lihtne ajaxi näide
Allikas: Lambda
<html> <head> <script> var request; var url; var response; var eresp; function myupdatefun() { //alert(request.readyState) if (request.readyState == 4) { //alert("Server is done!"); if (request.status == 200) { //alert("Server sent data ok!"); response = request.responseText document.getElementById('sisu').value= response; eresp=eval(response) //alert(eresp) //alert(eresp.length) for (i=0; i<eresp.length; i++) { alert(eresp[i]) } //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() { request = new XMLHttpRequest(); //url = "http://www.mysite.com" url = "http://localhost/cgi-bin/try.sh" request.open("GET", url, true); request.onreadystatechange = myupdatefun; request.send(null); } </script> <body> Tere kah! <p> <a href="javascript:ajaxcall()">proovi!</a> <p> <input type="text" id="sisu"></input> <div id="sisu2"></div> </body>