AJAX showCustomer()

前端之家收集整理的这篇文章主要介绍了AJAX showCustomer()前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

data.PHP

<?PHP 
header("Content-type: text/html; charset=utf-8"); 
$num = $_GET['q'];
if ($num == 1) {
	echo '苹果电脑,公司';
}elseif ($num == 2) {
	echo '百度';
}elseif ($num == 3) {
	echo '美国佳能';
}elseif ($num == 4) {
	echo '谷歌';
}

 ?>

<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","./data.PHP?q="+str,true);
xmlhttp.send();
}
</script>
</head>
<body>

<form action="" style="margin-top:15px;"> 
<label>请选择一位客户:
<select name="customers" onchange="showCustomer(this.value)" style="font-family:Verdana,Arial,Helvetica,sans-serif;">
<option value="1">Apple Computer,Inc.</option>
<option value="2">BAIDU,Inc</option>
<option value="3">Canon USA,Inc.</option>
<option value="4">Google,Inc.</option>
</select>
</label>
</form>
<br />
<div id="txtHint">客户信息将在此处列出 ...</div>

</body>
</html>

效果图:

原文链接:https://www.f2er.com/ajax/165170.html

猜你在找的Ajax相关文章