【发布时间】:2017-03-30 00:36:46
【问题描述】:
<html>
<head>
<title>List</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- Javascript code -->
<script>
function showUser(str) {
if (str == " ") {
document.getElementById("txtHint").innerHTML = " ";
return;
} else {
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
} else {
// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("txtHint").innerHTML = this.responseText;
}
};
xmlhttp.open("GET","getuser.php?q="+str,true);
xmlhttp.send();
}
}
</script>
<!-- CSS for HTML table -->
<style>
table {
width: 100%;
border-collapse: collapse;
}
table, td, th {
border: 1px solid black;
padding: 5px;
}
th {text-align: left;
}
</style>
</head>
<body>
<form>
<select name="users" onchange="showUser(this.value)">
<option value=" ">Select a person:</option>
<option value="1">Peter Griffin</option>
<option value="2">Lois Griffin</option>
<option value="3">Joseph Swanson</option>
<option value="4">Glenn Quagmire</option>
</select>
</form>
<div id="txtHint">Result from PHP script should appear here</div>
</body>
</html>
当我通过 Netbeans 在 Google Chrome 浏览器中运行以下 HTML 页面时,当我尝试从列表中选择一个人时遇到此错误(请参阅标题)。
xmlhttp.onreadystatechange = function()
这行代码和下面的代码似乎是基于 Chrome 的开发者工具的关注领域。
select name="users" onchange="showUser(this.value)
谁能指出需要改变的地方?
【问题讨论】:
标签: javascript php jquery html xmlhttprequest