填充另一个下拉数据库的下拉列表

时间:2016-06-17 16:25:12

标签: javascript php jquery ajax drop-down-menu

我在使用AJAX数据库从另一个下拉列表填充下拉值时遇到问题。所以基本上我的表单中有 Intake Courses 。因此,如果用户选择Intake A,则PHP和JQuery课程将在Courses选项中。我现在的问题是,在我选择进入A后,课程选项并没有给出任何价值。你能帮我么?感谢

这是AJAX代码

$(document).ready(function($) {
      var list_target_id = 'Courses'; //first select list ID
      var list_select_id = 'Iname'; //second select list ID
      var initial_target_html = '<option value="">Please select intake...</option>'; //Initial prompt for target select

      $('#'+list_target_id).html(initial_target_html); //Give the target select the prompt option

      $('#'+list_select_id).change(function(e) {
        //Grab the chosen value on first select list change
        var selectvalue = $(this).val();
        //alert(selectvalue);
        //Display 'loading' status in the target select list
        $('#'+list_target_id).html('<option value="">Loading...</option>');

        if (selectvalue == "") {
            //Display initial prompt in target select if blank value selected
           $('#'+list_target_id).html(initial_target_html);
        } else {
          //Make AJAX request, using the selected value as the GET
          $.ajax({url: 'CoursesDropdown.php?svalue='+selectvalue,
                 success: function(output) {
                    //alert(output);
                    $('#'+list_target_id).html(output);
                },
              error: function (xhr, ajaxOptions, thrownError) {
                alert(xhr.status + " "+ thrownError);
              }});
            }
        });
    });

这是PHP方面

<?php
            include "connect.php";

            $selectvalue = mysqli_real_escape_string($con, $_GET['svalue']);
            $checkuser = "Select Coursesname from courses Where CoursesIntake ='$selectvalue'";
            $result2 = mysqli_query($con, $checkuser);

            echo '<option value="">Please select...</option>';
            echo $result2;
            while ($row = mysqli_fetch_array($result2)) {
                //echo '<option value=" . $row["CoursesName"] . "> . $row["CoursesName"] . "</option>"';
                //echo '<option value=' . $row['Coursesname'] . '>' . $row['Coursesname'] . '</option>';
                echo '<option value="">Please select...</option>';
                echo '<option value="">Please select...</option>';
            }

            mysqli_close($con);
            ?>

0 个答案:

没有答案