Ajax下拉列表无效

时间:2018-05-14 06:33:47

标签: php html mysql ajax

我正在开发一个动态网站,用户可以通过证明位置和专家来搜索医生,如下所示:This is my main page

这是我的主页代码:

的index.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
        <title>AJAX</title>
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
    </head>
    <body>
        <form>
            <option value="0">-----select specialist-----</option>
            <?php
                $con=mysql_connect("localhost","root","");
                mysql_select_db("doctor_db",$con);
                $q=$_GET["q"];
                $sql="select * from specialty_tb where lid='".$q."'";
                $res=mysql_query($sql);
                while($ar=mysql_fetch_array($res)){
                    echo "<option value=".$ar[0].">".$ar[1]."</option>";
                }
            ?>
        </form>
    </body>
</html>

getstate.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
        <title>Untitled Document</title>
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
    </head>
    <body>
        <form>
            <option value="0">-----select doctor-----</option>
            <?php
                $con=mysql_connect("localhost","root","");
                mysql_select_db("doctor_db",$con);
                $q=$_GET["q"];
                $sql="select * from doctor_details where sid='".$q."'";
                $res=mysql_query($sql);
                while($ar=mysql_fetch_array($res)){
                    echo "<option value=".$ar[0].">".$ar[1]."</option>";
                }
            ?>
        </form>
    </body>
</html>

getdis.php

$json = json_decode($row['orders'], true);  // 2nd argument `true` converts json object into array.
$email = $json['email'];

这些是我的表

location_tbspecialty_tb doctor_details

问题是,当我从列表中选择位置时,我可以使用位置ID从该位置获取专家。但我无法获得医生名单。

例如: - 如果我选择Kannur的位置,我会收到Kannur的所有专家,如表中所示,如果我选择一位专家,比如麻醉师,我无法获得医生名单,他们是麻醉师。根据在doctor_details中输入的数据,我应该根据所提供的sid在第三个列表中获得“医生1”。

有人可以帮帮我吗?

3 个答案:

答案 0 :(得分:0)

我认为你应该追加字符串然后通过javascript添加select

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Untitled Document</title>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
    </head>
    <body>
    <form>
    <option value="0">-----select doctor-----</option>
    <?php
    $con=mysql_connect("localhost","root","");
    mysql_select_db("doctor_db",$con);
    $q=$_GET["q"];
    $sql="select * from doctor_details where sid='".$q."'";
    $res=mysql_query($sql);
    $option = '';
    while($ar=mysql_fetch_array($res))
    {
     $option .= "<option value=".$ar[0].">".$ar[1]."</option>";
    }
    echo $option;
    ?>
    </form>
    </body>
    </html>

答案 1 :(得分:0)

这一行只有变化

 <select id="ddlstate" name="ddlstate"  class="form-control"  
onchange="showHide(this.value)" >

您需要添加onchange事件,它才能正常工作。

答案 2 :(得分:0)

need to take another div tag in index.php: 
<div id="ddlstate_div">
<select id="ddlstate" name="ddlstate" class="form-control">
/////
</select>
 </div>

并更改ajax showHint函数:document.getElementById(“ddlstate”)。innerHTML替换为document.getElementById(“ddlstate_div”)。innerHTML

Add below tag in getstate.php:

    <select id="ddlstate" name="ddlstate" onchange="showHide(this.value)" class="form-control">


        </select>