ajax调用后无法附加到选择框

时间:2017-10-24 07:13:40

标签: javascript php jquery ajax

我调用了一个AJAX脚本来将数据填充到我的选择框中,我成功地获取了值,但它们没有附加到选择框。

 $('#choose_area').on('change',function(){
                var stateID = $(this).val();
                alert(stateID);
                if(stateID){
                    var xz=$.ajax({
                        type:'post',
                        url:'../processRequest/locationRefine.php?stateID='+stateID,
                        data:{'stID':stateID},
                        success: function(html){
                            $('#choose_loc').append(html);
                            $('#choose_clg').html('<option value="">Please choose Location of College</option>');
                        }
                    });
                    console.log(xz);
                }else{
                    $('#choose_loc').html('<option value="">Please choose state to apply</option>');
                    $('#choose_clg').html('<option value="">Please choose Location of College</option>');
                }
        });

          <div class="input-field col s4">
            <br>
            <label for="area_selection">Choose State Applying for</label>
            <?php
                include '../config/db.php';
                $sql = "SELECT * FROM college_info"; 
                $run = mysqli_query($conn,$sql);
                //$row = mysqli_num_rows($run)
            ?>
            <select id="choose_area">
            <option value="" disabled selected>Choose Your State</option>
            <?php
                    while($row = mysqli_fetch_array($run)){
                    //extract($row);
                    //print_r ($row);
                    //exit;
                        echo '<option value="'.$row['id'].'">'.$row['state'].'</option>';
            ?>
                    <?php
                    }
                    ?>
            </select>
            </div>
            <div class="input-field col s4">
            <br>
            <label for="location_selection">Choose Location of College</label>
            <select id="choose_loc">
                <option value="">Please Choose Location</option>
            </select>
            </div>
            <div class="input-field col s4">
            <br>
            <label for="college_selection">Choose College to apply</label>
            <select id="choose_clg">
                <option value="">Please Choose College</option>
            </select>
            </div>

我又试图根据查询无法使用$ .each函数追加选择值,有人能告诉我我在做什么错吗?

0 个答案:

没有答案