不会在PHP中使用Jquery和Ajax在Dynamic Dependent Select Box中加载值到下拉列表中

问题描述 投票:0回答:1

在这里,我使用Dynamic Dependent Select Box中的JqueryAjax尝试了PHP。在这里,当我选择specialization drop down box时,它必须在doctors中显示相关的doctor drop down box。在第一个drop down框中,将使用specialization反映php function,它在第一个drop down box中正确显示,但是在doctor drop down box中,它没有加载,但在ajax控制台中它已成功显示给相关医生。 >

我的查看页面如下:

        <?php
                    function load(){ 
                  include('phpquery/dbconnection.php');
                $output='';
                $sql="SELECT * from doctorspecilization";
                $result=mysqli_query($con,$sql);
                while($row=mysqli_fetch_array($result)){
   $output.='<option value="'.$row["specilization"].'">'.$row["specilization"].'</option>';
                               }
                            return $output;
                                    }
                                  ?>
                       <form class="form-horizontal" method="POST" id="form_apt">
                     <center>   <h2>Request an Appointment</h2>  </center>  <br><br>                    
                            <div class="form-group">
                                <label class="control-label col-sm-3">Doctor Specilization:</label>
                                <div class="col-sm-9">

                                    <select name="doctorspecilization" id="doctorspecilization">
                                <option value="">Select Specilization</option> 
                                     <?php echo load();   ?>

                              </select>
                              <span id="doctorspecilization-info" class="info text-danger"></span><br />

                                </div>
                            </div> 

                            <div class="form-group">
                                <label class="control-label col-sm-3">Doctor :</label>
                                <div class="col-sm-9">
                                    <select name="doctorname" id="doctorname">
                                <option value="">Select Doctor</option>                                     
                              </select>
                                </div>
                            </div> 

                            <div class="form-group">
                                <label class="control-label col-sm-3">Appointment Date:</label>
                                <div class="col-sm-9">
                                    <input type="date" id="date" name="date" class="form-control" placeholder="Enter your education">
                                    <span id="date-info" class="info text-danger"></span><br />
                                </div>


                            </div>

                            <div class="form-group mar-bot-0">
                                <div class="col-sm-offset-3 col-sm-9">
                                    <i class="waves-effect waves-light light-btn waves-input-wrapper" style=""><input type="button" value="APPLY NOW" id="apply" name="apply" class="waves-button-input"></i>
                                </div>
                            </div><br>
                            <center>  <div id="success_mes" class="text text-success">    </div>  </center> <br>

                        </form>

我的Ajax代码为

<script>

        //    start query
 $(document).ready(function () {

 $('#doctorspecilization').change(function () {

var doc_spec_id=$(this).val();

$.ajax({
            url: "phpquery/fetch_doctor_name.php", // Url to which the request is send
            method: "POST",             // Type of request to be send, called as method
            data: {doc_spec_id:doc_spec_id  },
            dataType:"text",

            success: function (data) {
                $("#doctorname").html(html);

            }

        });
    });
   });
</script>

我的fetch_doctor_name.php

<?php
include('dbconnection.php');
$output='';
$sql="SELECT * from users where specilization='".$_POST['doc_spec_id']."'";
$result=mysqli_query($con,$sql);
$output='<option value="">Select Doctor</option>';
while($row=mysqli_fetch_array($result)){

  $output.='<option value="'.$row["username"].'">'.$row["username"].'</option>';
}
echo $output;
?>

[请让我知道我在哪里弄错了。

这里,我在PHP中使用Jquery和Ajax尝试了动态相关选择框。在这里,当我选择“专业化”下拉框时,它必须在“医生”下拉框中显示相关的医生。首先...

javascript php jquery ajax
1个回答
0
投票

Hii,请参阅是否对您有帮助。当使用ajax获取响应时,我们需要指定数据将以哪种格式出现。

© www.soinside.com 2019 - 2024. All rights reserved.