ajax中的“拒绝访问”错误

时间:2011-04-28 09:24:50

标签: ajax

关于以下ajax代码我收到“Access is Denied”错误消息。在这种情况下,有人可以帮助我。

<html>
<head>
<script type="text/javascript">
function a()
{
var xmlhttp=new XMLHttpRequest();
xmlhttp.open("GET","load1.txt",true);
xmlhttp.onreadystatechange=function()
{
document.getElementById("hello").innerHTML=xmlhttp.requestText;
}
}
</script>
</head>
<body>
<input type="button" value="hello" onclick="a()"/>
<div id="hello"></div>
</body>
</html>

1 个答案:

答案 0 :(得分:0)

您在代码中表示为requestText,我认为应该是responseText

示例代码

<script type="text/javascript">
function loadXMLDoc()
{
var xmlhttp;
if (window.XMLHttpRequest){
  xmlhttp=new XMLHttpRequest();
}else{
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("myDiv").innerHTML= xmlhttp.responseText; 
    }
  }
xmlhttp.open("GET","ajax_info.txt",true);
xmlhttp.send();
}
</script>

<div id="myDiv">Let AJAX change this text</div>
<button type="button" onclick="loadXMLDoc()">Change Content</button>

http://www.w3schools.com/Ajax/tryit.asp?filename=tryajax_first

查看实时示例
相关问题