Ajax Asynchronous request PHP Data _php Tutorial

Source: Internet
Author: User

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, ...

  • 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.