Ajax asynchronously requests PHP data
Received a teacher's homework, the realization of the layout
If the department ID is entered, the department name only shows the corresponding ID, if there is no input, then display all, and then according to the name of the Department of I, in the section of the text box automatically display the department name of the major section. For example: Cardiovascular medicine was selected, and the Department of Internal Medicine was shown in its own major.
The main code is as follows:
Request department based on ID
function Showhint (str) { var xmlhttp; if (window. XMLHttpRequest) {//ie7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest (); } else {//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,keshi.php?q=+str,true); Xmlhttp.send ();}
keshi.php:
'; while (!! $rowDKQ = Fetchassoc ($resultDKQ)) { $hint. = '
'; $resultKSQ = Querydb (select Table_dake.id,table_keshi.sid,table_keshi.name from Table_dake,table_keshi where Table_dake.name= ' {$rowDKQ [' name ']} ' and table_keshi.sid=table_dake.id); while (!! $rowKSQ = Fetchassoc ($resultKSQ)) {$hint. = ''. $rowKSQ [' name ']. '; } $hint. = ''; }}//is not a number else {$resultDK = Querydb (select Table_dake.name from Table_dake); $hint = ' Department Name: '; while (!! $rowDK = Fetchassoc ($resultDK)) {$hint. = '; $resultKS = querydb (select Table_dake.id,table_keshi.sid,table_ Keshi.name from Table_dake,table_keshi where table_dake.name= ' {$rowDK [' name ']} ' and Table_keshi.sid=table_dake.id '; while (!! $rowKS = Fetchassoc ($resultKS)) {$hint. = ''. $rowKS [' name ']. '; } $hint. = '; }} $response = $hint; Output response echo $response;?> effect: ID not entered as, enter ID in: Next: Hundreds search: Add Google, Baidu and other search engines in the website
http://www.bkjia.com/PHPjc/907374.html www.bkjia.com true http://www.bkjia.com/PHPjc/907374.html techarticle Ajax Asynchronous request PHP data received a teacher's job, the implementation of the layout if Input Department ID, department name only display and ID corresponding, if not input, then show all, ...