/**//** * @author Ma Li */ /**//** * create a xmlHttpRequest object for other function * using */ var xmlHttp = createXmlHttpRequestObject(); function createXmlHttpRequestObject() ...{ // an xmlHttpRequest object var xmlHttp; // browser is IE if (window.ActiveXObject) ...{ try ...{ // create the ActiveX object xmlHttp =new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) ...{ // exception throwed xmlHttp =false; } } // browser is FireFox or OPERA or others else ...{ try ...{ // create the xmlHttpRequest object xmlHttp =new XMLHttpRequest(); } catch (e) ...{ // exception throwed xmlHttp =false; } } if (!xmlHttp) ...{ // Cann't create object alert("Error creating the XMLHttpRequest object."); } else ...{ // return the object return xmlHttp; } } /**//** * the user event trigger */ function process() ...{ // xmlHttp object is not busy, processing my request if (xmlHttp.readyState ==4|| xmlHttp.readyState ==0) ...{ // get the user name from the form textfield name = encodeURIComponent(document.getElementById("myName").value); // run the server script xmlHttp.open("GET", "quickstart.php?name="+name, true); // set the call back function xmlHttp.onreadystatechange = handleServerResponse; // send the request xmlHttp.send(null); } else ...{ // failed, then try again after 1 second setTimeout("process()", 1000); } } /**//** * the call back function */ function handleServerResponse() ...{ // processing complete if (xmlHttp.readyState ==4) ...{ // processing successful if (xmlHttp.status ==200) ...{ // get the XML document from the server xmlResponse = xmlHttp.responseXML; // get the root element of the XML document xmlDocumentElement = xmlResponse.documentElement; // get the first child of root eleemnt text content helloMessage = xmlDocumentElement.firstChild.data; // display the message in the div tag document.getElementById("divMessage").innerHTML = '<i>'+ helloMessage +'</i>'; // restart another process setTimeout("process()", 1000); } else ...{ // processing error alert("there was a problem accessing the server: "+ xmlHttp.statusText); } } }
/**//** * @author Ma Li *//**//** * create a xmlHttpRequest object for other function * using */var xmlHttp = createXmlHttpRequestObject();function createXmlHttpRequestObject()...{ // an xmlHttpR