【问题标题】:Why isn't this AJAX code showing any output in ASP.NET?为什么这个 AJAX 代码在 ASP.NET 中没有显示任何输出?
【发布时间】:2010-11-17 01:11:05
【问题描述】:
<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>

【问题讨论】:

  • 您可以尝试使用浏览器中的开发者工具对其进行调试。在 IE8 中你可以使用 F12 来启动它,在 Chrome 中它是 Ctrl+Shift+I,在 FireFox 中通常大多数人使用 firebug。

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


【解决方案1】:

试试这个警报(xmlhttp.responseText);看看你是否真的得到了 responseText 的任何价值,或者更好的是确保你真的得到了那个代码块

【讨论】:

  • 在哪里写警报(xmlhttp.responseText);声明
  • 将警报放在您拥有 document.getelementbyid 的位置。
猜你喜欢
  • 2021-04-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-02-24
  • 1970-01-01
相关资源
最近更新 更多