我想修改一個腳本從w3scools使用asp和ajax的組合來查詢數據庫並返回結果。查詢數據庫與Ajax和經典的ASP
下面是代碼:
<html>
<head>
<script type="text/javascript">
function showCustomer(str)
{
var xmlhttp;
if (str=="")
{
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","getcustomer.asp?q="+str,true);
xmlhttp.send();
}
</script>
</head>
<body>
<form action="">
<select name="customers" onchange="showCustomer(this.value)">
<option value="">Select a customer:</option>
<option value="ALFKI">Alfreds Futterkiste</option>
</select>
</form>
<br />
<div id="txtHint">Customer info will be listed here...</div>
</body>
</html>
我想與2個輸入字段來替換選擇字段。
有人可以告訴我如何修改JavaScript,以便兩個輸入值與查詢字符串一起傳遞,以及需要在窗體上更改以調用該函數。
謝謝
謝謝詹姆斯,那正是我要找的。輸入用於orderID和電子郵件用於檢索訂單數據。 – 2011-05-17 12:11:29
你應該在網址中命名第二個參數。 – 2011-05-17 12:12:57
@Gaby aka G.Petrioli - 哎呦 - 很好被發現 – 2011-05-17 12:14:24