在这里,我使用Dynamic Dependent Select Box
中的Jquery
和Ajax
尝试了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尝试了动态相关选择框。在这里,当我选择“专业化”下拉框时,它必须在“医生”下拉框中显示相关的医生。首先...
Hii,请参阅是否对您有帮助。当使用ajax获取响应时,我们需要指定数据将以哪种格式出现。