PHP データの Ajax 非同期リクエスト

WBOY
リリース: 2016-06-21 08:47:24
オリジナル
1223 人が閲覧しました

先生から課題を受け取り、実装したレイアウトは以下のとおりです:

部門 ID が入力されている場合は、その ID に対応する部門名のみが表示されます。入力されていない場合は、I 部門名の値に基づいて、対応する主な部門のテキスト ボックスが表示されます。部門名が存在する主な部門を自動的に表示します。例:循環器内科を選択した場合、対応する専攻科に内科が表示されます。

メインコードは次のとおりです:

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:

<!--?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;
ログイン後にコピー
'; $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 .= ''; ; } } // 数値ではありません { $resultDK = queryDB(select table_dake.name from table_dake); $hint = '部門名: などの検索エンジン



関連ラベル:
ソース:php.cn
このウェブサイトの声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。
最新の問題
人気のおすすめ
人気のチュートリアル
詳細>
最新のダウンロード
詳細>
ウェブエフェクト
公式サイト
サイト素材
フロントエンドテンプレート
私たちについて 免責事項 Sitemap
PHP中国語ウェブサイト:福祉オンライン PHP トレーニング,PHP 学習者の迅速な成長を支援します!