The returned value of AjaxphpxmlHttp. responseXML is null.

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.