为什么没有这个AJAX code显示ASP.NET任何输出? [英] Why isn't this AJAX code showing any output in ASP.NET?
本文介绍了为什么没有这个AJAX code显示ASP.NET任何输出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
<头=服务器>
<脚本类型=文/ JavaScript的>
函数loadXMLDoc()把
{
如果(window.XMLHtt prequest)
{// code为IE7 +,火狐,Chrome,歌剧,Safari
XMLHTTP =新XMLHtt prequest();
}
其他
{// code为IE6,IE5
XMLHTTP =新的ActiveXObject(Microsoft.XMLHTTP);
}
xmlhttp.onreadystatechange =功能()
{
如果(xmlhttp.readyState == 4和&放大器; xmlhttp.status == 200)
{
的document.getElementById('DIV1)的innerHTML = xmlhttp.responseText。
}
}
xmlhttp.open(GET,ajax_info.txt,真正的); //这个文本文件是在同一文件夹
xmlhttp.send();
}< / SCRIPT><身体GT;
<表ID =form1的=服务器>
< DIV ID ='DIV1>< H2>阿贾克斯是如何工作和LT; / H>< / DIV>
<按钮式=按钮的onclick =loadXMLDoc()把>更改内容和LT; /按钮> < /表及GT;
< /身体GT;
解决方案
试试这个警报(xmlhttp.responseText);看看是否你实际上得到任何价值的responseText,或更好,但要确保你实际上得到到code座
<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>
解决方案
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
这篇关于为什么没有这个AJAX code显示ASP.NET任何输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文