/*============================================================== Copyright 2006 Dynamic-Tools.net Do not remove this header. Script: Dynamic-Tools AJAX Toolkit Description: This script simplifies sending AJAX requests and handling the responses to those requests. The requests are threadsafe so you can send off as many at a time as you like. Author: Peter Wilkinson ==============================================================*/ // send a threadsafe XMLHTTPRequest function ajaxSend(method, url, parameters, responseHandler, asynchronous) { if (typeof method != 'string') { alert("Invalid request method."); return false; } method = method.toUpperCase(); if (method != 'POST' && method != 'GET') { alert("Invalid request method."); return false; } if (typeof parameters != 'string') parameters = ''; if (typeof asynchronous == 'undefined') asynchronous = true; // build the request var ajaxRequest = null; if (window.XMLHttpRequest) ajaxRequest = new XMLHttpRequest(); else if (window.ActiveXObject) ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP"); // bind the callback. function ajaxBindCallback() { if (ajaxRequest.readyState == 4) { if (ajaxRequest.status == 200 || ajaxRequest.status == 0) // is either valid XML or no { if (responseHandler) responseHandler(ajaxRequest); } else { if (ajaxRequest.status == 404) { alert("The requested service could not be found."); } else { alert("There was a problem retrieving the xml data:\n" + ajaxRequest.status + ":\t" + ajaxRequest.statusText + "\n" + ajaxRequest.responseText); } } } } // send the request if (ajaxRequest) { if (asynchronous) ajaxRequest.onreadystatechange = ajaxBindCallback; if (method == "GET") { url = url + '?' + parameters parameters = null; } ajaxRequest.open(method, url, asynchronous); if (method == 'POST') { ajaxRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8'); } ajaxRequest.send(parameters); if (!asynchronous) ajaxBindCallback(); } else alert("Unable to build XMLHttpRequest"); } function getXMLEntries(xmlBranch, tagName) { var tagList = xmlBranch.getElementsByTagName(tagName); var results = []; var length = tagList.length; for (var i=0; i < length; i++) { results.push(getXMLData(tagList[i])); } return results; } function getXMLData(xmlNode) { return xmlNode.firstChild ? xmlNode.firstChild.data : ''; } function ajaxLoad(action,parameters,output) { //setPointer(); // define the responseHandler function responseHandler(ajaxRequest) { var rx = new RegExp('parent_'); if (output.match(rx)){ output = output.substr(7,output.length); var outputDiv = parent.document.getElementById(output); } else { var outputDiv = document.getElementById(output); } var htmlSnippet = ajaxRequest.responseText; if(output!='') outputDiv.innerHTML = htmlSnippet; //resetPointer(); } // send the request. The post method is used because get restricts the amount of data that can be sent // to around 2000 chars and this app could potentially send more than that. ajaxSend('post', action, parameters, responseHandler); } function ajaxDo(action,parameters,output) { // define the responseHandler function responseHandler(ajaxRequest) { var htmlSnippet = ajaxRequest.responseText; eval(htmlSnippet); /* var outputDiv = document.getElementById(output); outputDiv.innerHTML = htmlSnippet; */ } // send the request. The post method is used because get restricts the amount of data that can be sent // to around 2000 chars and this app could potentially send more than that. ajaxSend('post', action, parameters, responseHandler); }