The returned value of AjaxphpxmlHttp. responseXML is null. php code
';echo'
';$name=$_GET['name'];$userName=array('WangWei','ZhouJianfei','MeiShibo','QuXinglin','WangYuming','LiaoGuihong','WangChenggao','ZhouQian');if(in_array(strtoupper($name),$userName)){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!';}echo '
';?>
var xmlHttp=createXmlHttpRequestObject();//get xmlHttpRequest objectfunction createXmlHttpRequestObject(){var xmlHttp;if(window.ActiveXObject){try{xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");}catch(e){xmlHttp=false;}}else{try{xmlHttp=new XMLHttpRequest();}catch(e){xmlHttp=false;}}if(!xmlHttp){alert("Error creating the XMLHttpRequest object!");}else{return xmlHttp;}}function process(){if(xmlHttp.readyState==4||xmlHttp.readyState==0){name=encodeURIComponent(document.getElementById("myName").value);xmlHttp.open("GET","quickstart.php?name="+name,true);xmlHttp.onreadystatechange=handleServerResponse;xmlHttp.send(null);}else{setTimeout('process()',1000);}}function handleServerResponse(){if(xmlHttp.readyState==4){if(xmlHttp.status==200){xmlResponse=xmlHttp.responseXML;alert(xmlHttp.responseXML);xmlDocumentElement=xmlResponse.documentElement;helloMessage=xmlDocumentElement.firstChild.data;document.getElementById('pMessage').innerHTML=''+helloMessage+'';setTimeout('process()',1000);}else{alert('There was a problem accessing hte server:'+xmlHttp.statusText);}}}
Alert (xmlHttp. responseXML); where is the return value null?
In addition, the php on the Alibaba free virtual host I use
Reply to discussion (solution)
Alert (xmlHttp. responseXML)
This statement is irresponsible.
If everything goes well, he is a DOMDocument Object and can see [Object] at most with alert.
So you should write
xmlResponse = xmlHttp.responseXML;if(xmlResponse.xml == '') { alert(xmlHttp.responseText); return;}In this way, no matter whether the XML format is incorrect or the php program is faulty, it will be exposed in the alert window.