
PHP – AJAX 与 MySQL
AJAX 可用来与数据库进行交互式通信。
AJAX 数据库实例
下面的实例将演示网页如何通过 AJAX 从数据库读取信息:
实例
function showUser(str)
{
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 person: Peter Griffin Lois Griffin Joseph Swanson Glenn Quagmire
{
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 person: Peter Griffin Lois Griffin Joseph Swanson Glenn Quagmire


常见问题
相关文章
猜你喜欢
- PHP 超级全局变量 2015-09-06
- PHP 文件上传 2015-09-06
- PHP MySQL 插入多条数据 2015-09-06
- AJAX 实时搜索 2015-09-06
- PHP String 2015-09-06
- PHP While 循环 2015-09-06
- PHP Cookies 2015-09-06
- PHP MySQL 读取数据 2015-09-06
- AJAX RSS Reader 2015-09-06
- PHP XML 2015-09-06