当前位置:Gxlcms > PHP教程 > php随笔2-php+ajax实现输入读取数据库显示匹配信息

php随笔2-php+ajax实现输入读取数据库显示匹配信息

时间:2021-07-01 10:21:17 帮助过:6人阅读

dropbox_index.php

主搜索引擎下拉框自动显示数据

dropbox.js

        var xmlHttp                        function showHint(str)        {            if (str.length==0)            {               document.getElementById("txtHint").innerHTML=""              return            }            xmlHttp=GetXmlHttpObject()            if (xmlHttp==null)              {                  alert ("Browser does not support HTTP Request")                  return              }             var url="responsepage.php"            url=url+"?q="+str            url=url+"&sid="+Math.random()            xmlHttp.onreadystatechange=stateChanged             xmlHttp.open("GET",url,true)            xmlHttp.send(null)        }                         //设置回调函数        function stateChanged()         {             if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")             {                 document.getElementById("txtHint").innerHTML=xmlHttp.responseText              }         }                        function GetXmlHttpObject()        {            var xmlHttp=null;            try             {                 // Firefox, Opera 8.0+, Safari                 xmlHttp=new XMLHttpRequest();            }            catch (e)            {                 // Internet Explorer                 try                  {                    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");                  }                 catch (e)                  {                    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");                  }             }            return xmlHttp;        }

dropbox.css

.txt{ height:22px; border:1px solid #cdcdcd; width:220px;border-right:none;} .btn{ background-color:#FFF; border:1px solid #CDCDCD;height:26px; width:70px;}

responsepage.php

";                 //echo "lastname:" . $row['LastName'] . "
"; //echo "age:" . $row['Age'] . "
"; } //echo $row['FirstName'] . "
"; } mysql_close($con); }?>

数据库:

结果:

人气教程排行