ajax-(myXmlHttpRequest.responseXML返回值为空问题

WBOY
Release: 2016-06-02 11:32:06
Original
1028 people have browsed it

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>
Copy after login

服务器代码是这样的:
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>
Copy after login
<code>这是为什么?新手,所以没啥悬赏。。求大神帮助。我快被这个错误折磨致死了。。。</code>
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template