根据w3schools.com XMLHttpRequest对象的开口的方法有三个参数: 1.方法 2. URL 3.一个布尔值,指示该呼叫是否是异步或不xmlhttp.open(“GET”,“ajax_info.txt”,true):我错过了什么?
其中一个例子中使用的文本文件的url参数。我复制了代码,并用自己的文本替换了文本文件,没有发生任何事情。我错过了什么?
这是我复制的代码:
这不叫XMLLocalFileRequest :)
尝试使用http://localhost/ajax_info.txt
为URL○:
<!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","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>
请原谅我的无知我是一个noob。我使用了:“\ http://localhost/ajax_info.txt”,并没有发生任何事情。谢谢您的帮助。 – MR1971 2014-09-22 08:59:05