我已经实现了示例。在这里,我只使用一个下拉列表检索数据。它工作正常。但是,如果我想对两个下拉列表执行相同的操作,则必须根据两个下拉列表的值来检索数据库中的值。我正在尝试如下:Ajax 脚本-
<script> // AJAX Implementation
function showCourses() {
str = document.getElementById("branch").value;
str1 = document.getElementById("sem").value;
if (str == "" || str1 == "") {
document.getElementById("txtHint").innerHTML = "";
return;
}
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("txtHint").innerHTML = xmlhttp.responseText;
}
}
xmlhttp.open("GET", "listCourseByAjax.php?p=" + str + "&q=" + str1, true);
xmlhttp.send();
}
</script>
下拉列表-
<select name="branch" onchange="showCourses(this.value)">
<option id="branch" value="0" selected>Select one</option>
<option id="branch" value="ISE">1/option>
<option id="branch" value="CSE">2</option>
<option id="branch" value="ME">3</option>
</select>
<select name="sem" onchange="showCourses(this.value)">
<option id="sem" value="0" selected>select one</option>
<option id="sem" value="I-P">I-P</option>
<option id="sem" value="I-C">I-C</option>
<option id="sem" value="II-P">II-P</option>
</select>
php文件——
$p = $_GET['p'];
$q = $_GET['q'];
$sql="SELECT * FROM course_details WHERE sem='" . $q . "' AND branch='" . $p . "'";
$result = mysql_query($sql);
echo "<table border='1'>
<tr>
<th>Course Code</th>
<th>Course Name</th>
<th>Course Instructor</th>
<th>Credit</th>
</tr>";
请帮我怎么做。