我正在学习 AJAX 并创建了这个简单的代码。我在文本框中输入了一些东西,它应该会在屏幕上弹出一些东西。当我单击一个按钮时,它能够工作,但现在我将它更改为一个文本框,它不再工作了。这是第一个包含 XML HTTP 请求数据和 HTML 代码的文件。
<html>
<head>
<script type="text/javascript">
function load() {
if (window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest();
} else {
xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
}
xmlhttp.onreadystatechange = function () {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
document.getElementById('results').innerHTML = xmlhttp.responseText;
}
}
xmlhttp.open('GET', 'test_ajax_return.php', true);
xmlhttp.send();
}
</script>
</head>
<body>
<form id="search" name="search">Type a name:
<br>
<input type="text" name="search_text" onkeydown="load();">
</form>
<div id="results"></div>
</body>
</html>
这是当用户在文本框中输入内容时我要打开的第二个文件。
<?php
echo 'something';
?>
[已解决]:感谢 Matt 提供的 Javascript 控制台。发现我编辑的一些评论毕竟影响了代码。我不认为 HTML 注释可以做到这一点。学过的知识。