为什么这个AJAX代码在ASP.NET中没有显示任何输出?

时间:2010-11-17 01:11:06

标签: asp.net ajax asp.net-ajax

<head runat="server">
<script type ="text/javascript">
   function LoadXMLDoc()
   {
        if (window.XMLHttpRequest)
        {// code for IE7+, Firefox, Chrome, Opera, Safari
            xmlhttp=new XMLHttpRequest();
        }
        else
        {// code for IE6, IE5
            xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
        xmlhttp.onreadystatechange=function()
        {
            if (xmlhttp.readyState==4 && xmlhttp.status==200)
            {
                document.getElementById("Div1").innerHTML=xmlhttp.responseText;
            }
        }
        xmlhttp.open("GET","ajax_info.txt",true); //this text file is in the same folder
        xmlhttp.send();
    }

</script>

<body>
    <form id="form1" runat="server">
        <div id="Div1"><h2>How Ajax works</h2></div>
    <button type="button" onclick="LoadXMLDoc()">Change Content</button>

   </form>
</body>

1 个答案:

答案 0 :(得分:0)

尝试此警报(xmlhttp.responseText);看看你是否真的为responseText获取了任何值,或者更好的是确保你实际上已经到达那个代码块