var xmlHttp; // Ravi Syamala, SWE 437 // standard create xml request object method. function createXmlHttpRequest() { if(window.ActiveXObject) { xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); } else if(window.XMLHttpRequest) { xmlHttp=new XMLHttpRequest(); } } function startRequest() { // create the request object createXmlHttpRequest(); // gather the value in the TextArea field var u1=document.form1.testPassage.value; // open the connection to the XML-returning servlet, note the escape on the testPassage form field // escape is needed in order to avoid truncating the message (new lines, etc). xmlHttp.open("GET","https://cs.gmu.edu:8443/offutt/servlet/ajaxstutter.ajaxstutter?testPassage="+escape(u1) ,true) // wire up an event reciever method (handleStateChange) for when the server responds. xmlHttp.onreadystatechange=handleStateChange; // null-terminate the stream to finish sending. xmlHttp.send(null); } function handleStateChange() { if(xmlHttp.readyState==4) { if(xmlHttp.status==200) { var message = xmlHttp.responseXML .getElementsByTagName("message")[0] .childNodes[0].nodeValue; // add list item start and end tags now // for this example, this ends up being easier than parsing more xml. message = message.replace(/!1/g, "
  • "); message = message.replace(/!2/g, "
  • "); // put the message in a nicely formatted (CSS) list. message = ""; // display the message in the results. document.getElementById("results").innerHTML=message; } else { alert("Error loading page "+ xmlHttp.status + ": "+xmlHttp.statusText); } } }