Heim > Artikel > Backend-Entwicklung > ajax-(myXmlHttpRequest.responseXML返回值为空问题
ajaxphpjshtml
代码是这样的:
showCities.php:
<code> <meta http-equiv="content-type" content="text/html; charset=utf-8"> <script type="text/javascript">function getXmlHttpObject(){ var xmlHttpRequest; if(window.ActiveXObject){ xmlHttpRequest=new ActiveXObject("Microsoft.XMLHTTP"); }else{ xmlHttpRequest=new XMLHttpRequest; } return xmlHttpRequest;} var myXmlHttpRequest=""; function getCities(){ myXmlHttpRequest=getXmlHttpObject(); if(myXmlHttpRequest){ var url="/ajax/showCitiesPro.php"; var data="province="+$('sheng').value; myXmlHttpRequest.open("post",url,true); myXmlHttpRequest.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); myXmlHttpRequest.onreadystatechange=chuli; myXmlHttpRequest.send(data); } } function chuli(){ if(myXmlHttpRequest.readyState==4){ if(myXmlHttpRequest.status==200){ window.alert(myXmlHttpRequest.responseXML); } } } function $(id){ return document.getElementById(id); }</script> <select id="sheng" onchange="getCities();"><!--onchange="getCities();"--> <option value="">---省---</option> <option value="zhejiang">浙江</option> <option value="jiangsu">江苏</option> </select> <select id="city"> <option value="">--城市--</option> </select> <select id="county"> <option value="">--县城--</option> </select> </code>
服务器代码是这样的:
showCityPro.php:
<code> <?php header("Content-Type:text/xml;charset=utf-8"); header("Cache-Control: no-cache"); //接收用户选择的省 $province=$_POST['province']; echo "接收到的数据是:"; ?> window.alert(myXmlHttpRequest.responseXML);接收到的一直是null</code>
<code>这是为什么?新手,所以没啥悬赏。。求大神帮助。我快被这个错误折磨致死了。。。</code>