// JavaScript Document var ajaxRequest = null; // The XMLHTTPREQUEST object function initialiseAjax() { if (ajaxRequest!=null) { //Close the request as a new request has just been started ajaxRequest.abort(); ajaxRequest = null; return initialiseAjax(); } if(window.XMLHttpRequest && !(window.ActiveXObject)) { try { ajaxRequest = new XMLHttpRequest(); } catch(e) { ajaxRequest = null; } // branch for IE/Windows ActiveX version } else if(window.ActiveXObject) { try { ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP"); } catch(e) { try { ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) { ajaxRequest = null; } } } return true; } function convertArguments(args) { var args_txt = ""; for (var key in args) { if (args_txt!="") { args_txt += "&"; } args_txt += encodeURIComponent(key) + "=" + encodeURIComponent(args[key]); } return args_txt; } /** * Helper for creating a simple ajax query, which takes in a callback */ function simpleAjaxQuery(url, args, callback, async) { if (async == null) { async = true; } if (!initialiseAjax()) { return false; } if (ajaxRequest!=null) { if (async) { ajaxRequest.open('POST', url, async); ajaxRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); ajaxRequest.onreadystatechange = callback; ajaxRequest.send(convertArguments(args)); } else { ajaxRequest.open('POST', url, async); ajaxRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); //ajaxRequest.onreadystatechange = callback; ajaxRequest.send(convertArguments(args)); callback(ajaxRequest); } } else { alert ("Failed to init"); } return true; } /** * Helper for creating an ajax query that executes any resulting data on the clients side */ function simpleAjaxQueryExec(url, args) { simpleAjaxQuery(url, args, function() { if (ajaxRequest.readyState==4) { try { if (ajaxRequest.status == 200) { //Data received var response = ajaxRequest.responseText; ajaxRequest = null; eval(response); } else { ajaxRequest = null; } } catch (e) { ajaxRequest = null; } } } ); }