ajax

2011-04-28 97 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