我有一个 AJAX 下拉菜单,它根据三个不同的参数为用户提供一系列选项 - 一旦选择了这些参数,就会在下面生成一个列表。
当用户点击和项目时,他会被带到:
legat.php?id=[number]
我的问题是,当用户go back
在浏览器中按下“”按钮时,AJAX 列表不再显示生成的列表。
下拉菜单中的输入(“下拉菜单selections
”)相同,但不会生成下面的列表。
这是一个很大的可用性缺陷,因为用户将不得不再次选择这三个参数。
我该如何解决这个问题?
JavaScript:
function findLegater(val1, val2, val3) {
var stu = document.getElementById(val1).value
var ud = document.getElementById(val2).value
var kva = document.getElementById(val3).value
if (stu=="N" && ud =="0" && kva =="0") {
document.getElementById("txtHint").innerHTML="";
}
else {
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","getlegat.php?s="+stu+"&u="+ud+"&k="+kva,true);
xmlhttp.send();
}
}
PHP(接收输入):
$s=$_GET["s"];
$u=$_GET["u"];
$k=$_GET["k"];
include 'msql/msql-connect.php';
if ($s!= "N" && $u != "0" && $k!="0") {
$query = "SELECT * FROM legater WHERE studiegrad LIKE '%$s%' and studie LIKE '%$u%' and kvartal LIKE '%$k%'";
}
else if ($s!= "N" && $u == "0" && $k=="0") {
$query = "SELECT * FROM legater WHERE studiegrad LIKE '%$s%'";
}
else if ($s!= "N" && $u != "0" && $k=="0") {
$query = "SELECT * FROM legater WHERE studiegrad LIKE '%$s%' and studie LIKE '%$u%'";
}
else if($s== "N" && $u != "0" && $k=="0") {
$query = "SELECT * FROM legater WHERE studie LIKE '%$u%'";
}
else if($s== "N" && $u != "0" && $k!="0") {
$query = "SELECT * FROM legater WHERE studie LIKE '%$u%' and kvartal LIKE '%$k%'";
}
else if($s== "N" && $u == "0" && $k!="0") {
$query = "SELECT * FROM legater WHERE kvartal LIKE '%$k%'";
}
else if($s!= "N" && $u == "0" && $k!="0") {
$query = "SELECT * FROM legater WHERE studiegrad LIKE '%$s%' and kvartal LIKE '%$k%'";
}
// Execute query
$result = mysql_query($query) or die ("Error in" . $query);
$number = mysql_num_rows($result);
// Check result
if ($number == 0) {
echo "Ingen legater fundet";
}
else {
while ($row = mysql_fetch_array($result)) {
echo "<li><a href=\"legat.php?id=" . $row['id'] . "\">" . $row['navn'] . "</a> </li>";
}
}
// free result set memory
mysql_free_result($result);
// close connection
mysql_close($connection);