我想修改一个脚本从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