Php 2-php + ajax allows the input to read the database and display matching information. 2-phpajax_PHP tutorial

Source: Internet
Author: User
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...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.