Php 2-php + ajax enables the input to read the database and display the matching information, 2-phpajax. Php 2-php + ajax allows the input to read the database and display matching information. 2-phpajaxdropbox_index.php! DOCTYPEhtmlPUBLIC-W3CDTDXHTML1.0TransitionalENwww.w3.orgTR php casually 2-php + ajax achieve input read database display matching information, 2-phpajax
Dropbox_index.php
The data is automatically displayed in the drop-down list of the main search engine.
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)} // sets the callback 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) ;}?>
Database:
Result:
Dropdropdropdropdropdropdropdropdropdropdropdropdropdropdropdropdropdropdrop! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR...