php+ajax 實(shí)現(xiàn)輸入讀取數(shù)據(jù)庫顯示匹配信息
廢話不多說了,直接跟大家貼代碼了
dropbox_index.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>主搜索引擎下拉框自動(dòng)顯示數(shù)據(jù)</title> </head> <script src="js/dropbox.js" type="text/javascript"></script> <link href="css/dropbox.css" type="text/css" rel="stylesheet"/> <body> <form action="" method="post" enctype="multipart/form-data"> <input name="txt" id="txt" class="txt" type="text" onkeyup ="showHint(this.value)" /> <input type="submit" class="btn" name="submit" value="Upload" /><br /> <span id="txtHint" class="file-box"></span> </form> </body> </html>
dropbox.js ajax
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) } //設(shè)置回調(diào)函數(shù) 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
<?php //get the q parameter from URL $q=$_GET["q"]; //全部小寫化 $q=strtolower($q); //非空驗(yàn)證 if(isset($q) && $q != '') { $con = mysql_connect("localhost","root","lifu"); if(!$con) { die('Could not connect: ' .mysql_error()); } mysql_select_db("my_db",$con); $sql = "select * from persons"; //$sql="SELECT FirstName FROM Persons where Firstname like '%$q%'"; $result =mysql_query($sql,$con); while($row = mysql_fetch_array($result)) { //匹配判斷 if(stristr(strtolower($row['FirstName']),$q)) { //echo "-----------------Persons-----------------"; echo /* "firstname:" .*/ $row['FirstName'] . "<br />"; //echo "lastname:" . $row['LastName'] . "<br />"; //echo "age:" . $row['Age'] . "<br />"; } //echo $row['FirstName'] . "<br />"; } mysql_close($con); } ?>
數(shù)據(jù)庫:
以上就是本文給大家介紹的php+ajax 實(shí)現(xiàn)輸入讀取數(shù)據(jù)庫顯示匹配信息的全部內(nèi)容,希望大家喜歡。
- ajax php 實(shí)現(xiàn)寫入數(shù)據(jù)庫
- php從數(shù)據(jù)庫中獲取數(shù)據(jù)用ajax傳送到前臺(tái)的方法
- Ajax PHP 邊學(xué)邊練 之三 數(shù)據(jù)庫
- PHP jQuery+Ajax結(jié)合寫批量刪除功能
- php+ajax實(shí)現(xiàn)圖片文件上傳功能實(shí)例
- php的ajax簡單實(shí)例
- php+ajax實(shí)現(xiàn)無刷新動(dòng)態(tài)加載數(shù)據(jù)技術(shù)
- php采用ajax數(shù)據(jù)提交post與post常見方法總結(jié)
- ThinkPHP中使用ajax接收json數(shù)據(jù)的方法
- php+ajax+jquery實(shí)現(xiàn)點(diǎn)擊加載更多內(nèi)容
- PHP+jQuery+Ajax實(shí)現(xiàn)用戶登錄與退出
- php + ajax 實(shí)現(xiàn)的寫入數(shù)據(jù)庫操作簡單示例
相關(guān)文章
laravel自定義分頁的實(shí)現(xiàn)案例offset()和limit()
今天小編就為大家分享一篇laravel自定義分頁的實(shí)現(xiàn)案例offset()和limit(),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2019-10-10在laravel中實(shí)現(xiàn)事務(wù)回滾的方法
今天小編就為大家分享一篇在laravel中實(shí)現(xiàn)事務(wù)回滾的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2019-10-10CI框架(CodeIgniter)實(shí)現(xiàn)的數(shù)據(jù)庫增刪改查操作總結(jié)
這篇文章主要介紹了CI框架(CodeIgniter)實(shí)現(xiàn)的數(shù)據(jù)庫增刪改查操作,結(jié)合實(shí)例形式總結(jié)分析了CI框架針對(duì)mysql數(shù)據(jù)庫增刪改查操作的模型、控制器及視圖相關(guān)定義與使用技巧,需要的朋友可以參考下2018-05-05基于ThinkPHP5.0實(shí)現(xiàn)圖片上傳插件
thinkphp5.0 圖片上傳插件可預(yù)覽裁剪圖片和保存原圖片,執(zhí)行裁剪圖片后會(huì)刪除 裁剪的原圖片目錄,以便減少空間。具體實(shí)現(xiàn)代碼大家參考下本文2017-09-09php實(shí)現(xiàn)對(duì)短信驗(yàn)證碼發(fā)送次數(shù)的限制實(shí)例講解
這篇文章主要介紹了php實(shí)現(xiàn)對(duì)短信驗(yàn)證碼發(fā)送次數(shù)的限制實(shí)例講解,案例中列舉了具體代碼實(shí)現(xiàn),有感興趣的同學(xué)可以學(xué)習(xí)下2021-03-03在Mac OS上搭建PHP的Yii框架及相關(guān)測(cè)試環(huán)境
這篇文章主要介紹了在Mac OS上搭建PHP的Yii框架及相關(guān)測(cè)試環(huán)境的方法,Mac自帶Apache與PHP等軟件,因而搭建開發(fā)環(huán)境時(shí)非常舒適,需要的朋友可以參考下2016-02-02老司機(jī)傳授Ubuntu下Apache+PHP+MySQL環(huán)境搭建攻略
這篇文章主要介紹了Ubuntu下Apache+PHP+MySQL環(huán)境搭建攻略,文中采用的是LoadModule加載模塊的方式將PHP與Apache服務(wù)器程序連接,需要的朋友可以參考下2016-03-03