Home > Backend Development > PHP Tutorial > Ajax asynchronous request for PHP data_PHP tutorial

Ajax asynchronous request for PHP data_PHP tutorial

WBOY
Release: 2016-07-13 10:14:59
Original
1291 people have browsed it

Ajax asynchronous request for PHP data

I received an assignment from the teacher, and the implemented layout is as shown below:

If the department ID is entered, only the department name corresponding to the ID will be displayed. If not, all will be displayed. Then based on the value of the I department name, the text box in the corresponding major department will automatically display the major department where the department name is located. . For example: if Cardiovascular Medicine is selected, Internal Medicine will be displayed in the corresponding major department.

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();
}
Copy after login

keshi.php:

<!--?php
/*防止恶意调用*/
define(TEST,'test');
// 引入文件
include_once 'mysql.func.php';
// 数据库初始化
connectMySQL();
selectDB();
setZiFuJi();

//获得来自 URL 的 q 参数
$q=$_GET[q];
//如果 q 是数字或者数字字符串
if (is_numeric($q))
  {
    $q = intval($q);
    $hint=;
    $resultDKQ = queryDB(select name from table_dake where id=$q);
    $hint = '科室名字:<select name=ksname id=ksname onchange=show(this.options[this.selectedIndex].value)-->&#39;;
    while (!!$rowDKQ = fetchAssoc($resultDKQ))
    {
      $hint .= &#39;
Copy after login
'; $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 .= ''; } $hint .= '' ; } } // Not a number else { $resultDK = queryDB(select table_dake.name from table_dake); $hint = 'Department name:

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/907374.htmlTechArticleAjax asynchronous request for PHP data received an assignment from the teacher. The implemented layout is as shown in the figure: If the department ID is entered, The department name will only display the one corresponding to the ID. If no input is entered, all will be displayed...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template