首页 > 解决方案 > Ajax for dependent dropdown is not working in online server

问题描述

I have some issues in my ajax function, the dependent dropdown here i have attached my UI design is working good in localhost but once make it online it doesn't support.Can someone help me to solve this issue

Ajax code:

<script>
    function getClo(val) {
      var Sid = document.getElementById("usrID").value;
      var Auser_nm = document.getElementById("usrNM").value;
      document.getElementById("AuserID").value = Sid;
      document.getElementById("AuserNM").value = Auser_nm;
          
             $.ajax({
              type: "POST",
              url: "get_col.php",
              data: "courseid=" + val + "&staff_id=" + Sid,
              success: function(data){
                $("#clo_list").html(data);
              }
              });
            }
            </script>

dependent dropdown code:

<select name="coursecode-list" id="coursecode-list" class="course" onchange="getClo(this.value);">
    <option value="">Select Course</option>
    <?php 
$sql = mysqli_query($connection,"SELECT * FROM course"); 
while ($row=mysqli_fetch_array($sql))
{ ?>
        
  <option value="<?php echo $row['coursecode'];?>">
    <?php echo $row['coursecode']." ".$row['coursename']; ?>
  </option>
<?php 
}
?>
     </select>

<select id="clo_list" name="clo_list" class="course" >
    <option value="">Select CLO</option>
    </select>

get.col.php file code:

<?php
require_once ("database.php");

    $query ="SELECT * FROM clo WHERE coursecode = '" . $_POST["courseid"] . "' and
     staff_id = '" . $_POST["staff_id"] . "'";
    $results = $dbhandle->query($query);
?>
    <option value="">Select CLO</option>
<?php
    while($rs=$results->fetch_assoc()) {
?>
    <option value="<?php echo $rs["id"]; ?>"><?php echo $rs["clo"]; ?></option>
<?php

}
?>

标签: phpjqueryajaxdatabasedropdown

解决方案


推荐阅读