function showUser(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","getuser.php?q="+str,true);
xmlhttp.send();
}
Select a User:
Please Choose
Peter Griffin
Lois Griffin
Glenn Quagmire
Joseph Swanson
该段代码展示了如何使用Ajax异步请求从`getuser.php`获取用户信息。当用户从下拉菜单中选择一个用户时,通过在URL中附加查询参数`q`发送GET请求。当请求成功并返回响应时,将数据显示在ID为`txtHint`的元素内。
990

被折叠的 条评论
为什么被折叠?



