2013-08-21 329 views
0

我有一個AJAX下拉菜單,根據三個不同的參數爲用戶提供一系列選項 - 一旦選擇了這些選項,就會在下面生成一個列表。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); 
+0

見http://www.jscripters.com/ajax-disadvantages-and-advantages/對AJAX的缺點。 – jeff

+1

'mysql_'已棄用。改爲使用'mysqli'。而'mysql_num_rows'則完全浪費了服務器的能力。改爲使用'SELECT COUNT(id)作爲id_rows'。 – M1K1O

回答

0

您可以使用會議這個......當用戶從下拉選擇向下將其保存到會話.. 在頁面加載獲取ID 從會議並將其發送到服務器,得到結果..後會話結束銷燬它