"Access Denied" error in ajax
on the following ajax code iam getting a "Access is Denied" error message.Can somebody help me in this context.
<html>
<head>
<script type="text/javascript">
function a()
{
var xmlhttp=new XMLHttpRequest();
xmlhttp.open("GET","load1.txt",true);
xmlhttp.onreadystatechange=function()
{
d开发者_JAVA百科ocument.getElementById("hello").innerHTML=xmlhttp.requestText;
}
}
</script>
</head>
<body>
<input type="button" value="hello" onclick="a()"/>
<div id="hello"></div>
</body>
</html>
You have denoted as requestText in your code, i think that should be responseText
Example code
<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>
View the live example at http://www.w3schools.com/Ajax/tryit.asp?filename=tryajax_first
精彩评论