var xhr; function showDateAndTime() { sendRequest("dateAndTime.ajax", // the URL processAjaxCall); // the callback function } function sendRequest(url, handler) { initXHR(); xhr.onreadystatechange = handler; // set callback function xhr.open("GET", url, true); // open asynchronous GET request xhr.send(null); // send the request without params } function initXHR() { if(window.XMLHttpRequest) { xhr = new XMLHttpRequest(); } else if(window.ActiveXObject) { xhr = new ActiveXObject("Microsoft.XMLHTTP"); } } function processAjaxCall() { if(xhr.readyState == 4) { // if the request is finished... if(xhr.status == 200) { // ...and everything's okay // Get the dateDiv DIV and configure it // with the response text var dateDiv = window.document.getElementById("dateDIV"); dateDiv.innerHTML = xhr.responseText; } } }