// This function performs AJAX calls. // Target must be the ID of the HTML to update (uses innerHTML) // For sending data to the server, set the target as false. function AJAX(url,data,target){ // Create xmlHttp object for AJAX calls var xmlHttp; if (window.XMLHttpRequest){ xmlHttp = new XMLHttpRequest(); } else if (window.ActiveXObject){ xmlHttp = new ActiveXObject("Msxml2.XMLHTTP"); } xmlHttp.onreadystatechange = function(){ if(xmlHttp.readyState == 4 && xmlHttp.status == 200 && target != false){ if(document.getElementById(target).tagName.toLowerCase() == 'textarea'){ document.getElementById(target).value = xmlHttp.responseText; } else { document.getElementById(target).innerHTML = xmlHttp.responseText; } } } xmlHttp.open("POST",url,true); xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); xmlHttp.setRequestHeader("Content-length", data.length); xmlHttp.setRequestHeader("Connection", "close"); xmlHttp.send(data); } // This function handles AJAX errors gracefully. function ajaxError(e){ return false; } // Main function for retrieving data using AJAX functions above // Target must be the ID of the element to update. function getData(parameters,target){ var url = "ajax"; var data = parameters + "&nocache=" + Math.random(); try{ var response = AJAX(url,data,target); } catch(e) { return ajaxError(e); } }