我已经开始通过W3Schools网站上的AJAX教程工作,并且我的第一个示例甚至不会运行。为什么不这样做呢?它在浏览器中打开,但点击按钮时没有任何反应。第一个AJAX示例不会运行
教程URL;
https://www.w3schools.com/js/tryit.asp?filename=tryjs_ajax_ie
这里是我在记事本++
<!DOCTYPE html>
<html>
<body>
<h1>The XMLHttpRequest Object</h1>
<p id="demo">Let AJAX change this text.</p>
<button type="button" onClick="loadDoc()">Change Content</button>
<script>
function loadDoc() {
var xhttp;
if (window.XMLHttpRequest) {
// code for modern browsers
xhttp = new XMLHttpRequest();
} else {
// code for IE6 and IE5
xhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("demo").innerHTML = this.responseText;
}
};
xhttp.open("GET", "ajax_info.txt", true);
xhttp.send();
}
</script>
</body>
</html>
创建了HTML页面通过我在记事本中选择Run >>铬运行HTML网页++(但尝试Firefox和IE太)。 ajax_info.txt文件与HTML文件位于同一位置。这是它的内容;
AJAX不是一种编程语言。
AJAX是一种从网页访问Web服务器的技术。
AJAX代表Asyncronous JavaScript和XML。
你在浏览器调试器中有任何错误吗?也许你还需要一个Web服务器来完成这样的请求。 – alpham8
@ alpham8没有错误。该教程没有提到任何有关Web服务器的信息我编辑了“它在浏览器中打开的问题,但是当我点击按钮时没有任何反应” – AJF
它可以使用这个网址:https://www.w3schools.com/js/ajax_info.txt? – alpham8