var jmAjax = function() { /* initialize XmlHttp Object */ this.xmlHttp = false; /*@cc_on @*/ /*@if (@_jscript_version >= 5) try { this.xmlHttp = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { this.xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e2) { this.xmlHttp = false; } } @end @*/ // if we don't have an object at this point, and the XMLHttpRequest object exists, sing halleluja! if (!this.xmlHttp && typeof(XMLHttpRequest) != 'undefined') { try { this.xmlHttp = new XMLHttpRequest(); } catch (e) { this.xmlHttp = false; } } if (!this.xmlHttp) { throw "AJAX Not Supported by your browser. Please install Firefox 2 or greater. Goto: http://www.getfirefox.com."; } /** * The response text */ this.responseText = null; /** * The response in XML format */ this.responseXML = null; /** * Called when request is successful (200 http status code) * * You need to override this to get it's effect. */ this.callbackSuccess = function() { }; /** * Called when request failed (http status is first argument) * * You need to override this to get it's effect. */ this.callbackFailure = function(status) { }; /** * Private: sets onreadystatechange xmlHttp callback */ this.onreadystatechange = function() { var ajaxObj = this; return function() { // request completed if (ajaxObj.xmlHttp.readyState == 4) { ajaxObj.responseText = ajaxObj.xmlHttp.responseText; ajaxObj.responseXML = ajaxObj.xmlHttp.responseXML; if (ajaxObj.xmlHttp.status == 200) { ajaxObj.callbackSuccess(); } else { ajaxObj.callbackFailure(ajaxObj.xmlHttp.status); } } }; } /** * Sends a GET request to the specified URL */ this.get = function(url) { this.xmlHttp.open("GET", url, true); this.xmlHttp.onreadystatechange = this.onreadystatechange(); this.xmlHttp.send(null); } /** * Sends a POST request to the specified URL with specified data * * Post data is name=value pairs */ this.post = function(url, postdata) { this.xmlHttp.open("POST", url, true); this.xmlHttp.onreadystatechange = this.onreadystatechange(); this.xmlHttp.setRequestHeader("Content-Type", "text/plain"); this.xmlHttp.send(postdata); } /** * Sends a XML POST request to the specified URL with specified XML data * * XML data is an XML document (with root element the works) */ this.post_xml = function(url, xmldata) { this.xmlHttp.open("POST", url, true); this.xmlHttp.onreadystatechange = this.onreadystatechange(); this.xmlHttp.setRequestHeader("Content-Type", "text/xml"); this.xmlHttp.send(xmldata); } }; function parseJSON(json){return(/^[\],:{}\s]*$/.test(json.replace(/\\./g,'@').replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,']').replace(/(?:^|:|,)(?:\s*\[)+/g,'')))?eval('('+json+')'):{}}