ajax

2011-04-28 33 views
0

上的“访问被拒绝”错误在以下ajax代码我得到一个“访问被拒绝”错误消息。可以帮助我在这方面的人。ajax

<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> 
+0

的活生生的例子作为错误说乌尔否认访问该特定文件..检查您是否有权访问load1.txt – Vijay 2011-04-28 09:34:29

+0

是的,我有读取写入权限。:-) – 2011-04-28 09:37:01

回答

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

+0

仍然是问题持续存在的问题。 – 2011-04-28 09:52:37

+0

@Bivin拉文德兰还存在这个问题吗? – Vijay 2011-05-04 06:33:09

+0

没有。谢谢你的帮助...... :-) – 2011-05-06 09:30:33