Im新手到AJAX並試圖運行下面這段代碼,但它不工作... Ajax_info.txt文件位於我的本地驅動器。AJAX代碼不能按預期工作
<!DOCTYPE html>
<html>
<head>
<script>
function loadXMLDoc()
{
var xmlhttp;
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("myDiv").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","c:/python27/ajax_info.txt",true);
xmlhttp.send();
}
</script>
</head>
<body>
<div id="myDiv"><h2>Let AJAX change this text</h2></div>
<button type="button" onclick="loadXMLDoc()">Change Content</button>
</body>
</html>
你可能想看看http://stackoverflow.com/questions/7683596/xmlhttprequest-for-local-files雖然如果你正在學習AJAX,你可能會想使用本地Web服務器並從它加載文件而不是文件系統。 – tvanfosson
如果以下答案中的任何一個提出瞭解決方案,請點擊答案旁邊的複選標記以接受答案。這將有助於未來用戶搜索相同問題的答案。謝謝。 – SnareChops