kraleigh Posted March 25, 2008 Share Posted March 25, 2008 I have some code that is throwing an error because it is looking for an object, but my javascript is not as good as I would like it to be. So to begin with I have an html page that calls process() using onload() in this page is a text box with the id="myName" the exact error occurs in the handleServerResponse() function error = //get the text message, which is in the first child of the document element helloMessage = xmlDocumentElement.firstChild.data; evidently helloMessage is supposed to receive an object but dosen't I tried using alerts to pin point the exact problem but I don't know what xmlDocumentElement.firstChild.data; is supposed to do?? the php is really straight forward and is called with this line of code xmlHttp.open("GET", "quckstart.php?name=" + name, true); I'll post this code under the javascript I think the problem is that the php page is not returning an object but how do I check this? //the process function & the handleServerResponse functions function process(){ //proceed only if the xmlhttp object isn't busy if(xmlHttp.readyState == 4 || xmlHttp.readyState == 0){ //retrive the name typed by the user on the form name = encodeURIComponent(document.getElementById("myName").value); //execute the quickstart.php page from the server xmlHttp.open("GET", "quckstart.php?name=" + name, true); //define the method to handle server responses xmlHttp.onreadystatechange = handleServerResponse; //make the server request xmlHttp.send(null); } else { // if the connection is busy try again after one second setTimeout('process()', 1000); }//end function process() } //executed automatically when a messageis received from the server function handleServerResponse(){ //move forward only if the transactiion has completed if(xmlHttp.readyState == 4){ //status of 200 indicates the transaction completed successfully if(xmlHttp.status == 200){ //extract the xml retrived from the server xmlResponse = xmlHttp.responseXML; //obtain the document element (the root element) of the xml structure xmlDocumentElement = xmlResponse.documentElement; //get the text message, which is in the first child of the document element helloMessage = xmlDocumentElement.firstChild.data; //update the client display using the data received from the server document.getElementById("divMessage").innerHTML = '<i>' + helloMessage + '</i>'; //restart sequence setTimeOut('process()', 1000); } else {//a http status different than 200 signals an error alert("there was a problem accessing the server: " + xmlHttp.StatusTest); } } }//end function handleserverresponse() // begin php scripting <?php //we'll generate xml output header('Content-Type: text/xml'); //generate xml header echo '<?xml version="1.0" encoding="URF-8" standalone="yes"?>'; // create the <response element echo '<response>'; //retrive the user name $name = $_GET['name']; //generate output depending on the user name received from client $userNames = array('CRISTIAN', 'BOGDAN', 'FILIP', 'MIHAI', 'YODA'); if (in_array(strtoupper($name), $userNames)) echo 'Hello, master ' . htmlentities($name) . '!'; else if (trim($name) == '') echo 'Stranger, please tell me your name!'; else echo htmlentities($name) . ', I don\'t know you!'; //close the <response> element echo '</response>'; ?> //any insight would be greatly appreciated // thank you // kevin Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.