function AjaxResult(success, item) { this.success = success; this.item = item; } /* * Returns a new XMLHttpRequest object, or false if this browser * doesn't support it */ function newXMLHttpRequest() { try { return new ActiveXObject('Msxml2.XMLHTTP'); } catch (e1) {} try { return new ActiveXObject('Microsoft.XMLHTTP'); } catch (e2) {} try { return new XMLHttpRequest(); } catch (e3) {} return false; } /* * Returns a function that waits for the specified XMLHttpRequest * to complete, then passes its XML response * to the given handler function. * req - The XMLHttpRequest whose state is changing * responseXmlHandler - Function to pass the XML response to */ function getReadyStateHandler(req, responseXmlHandler) { // Return an anonymous function that listens to the // XMLHttpRequest instance return function () { // If the request's status is "complete" if (req.readyState == 4) { // Check that a successful server response was received if (req.status == 200) { // Pass the XML payload of the response to the // handler function responseXmlHandler(req.responseText); } else { // An HTTP problem has occurred alert("HTTP error: "+req.status); } } } } function ajaxRequest(url, handler) { var req = newXMLHttpRequest() || alert("No ajax! AHHH!"); req.onreadystatechange = getReadyStateHandler(req, handler); req.open("GET", url, true); req.send(null); }