Why isn't this AJAX code showing any output in ASP.NET?

丶灬走出姿态 提交于 2019-12-12 02:23:44

问题


<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:


try this alert(xmlhttp.responseText); to see if you are actually getting any value for responseText, or better yet to make sure you are actually getting to that code block



来源:https://stackoverflow.com/questions/4200645/why-isnt-this-ajax-code-showing-any-output-in-asp-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!