如何使用jquery显示选择框内的数据值?

如何使用jquery显示选择框内的数据值?,jquery,Jquery,代码: get-city.php <script> $(document).ready(function() { $("#where_to_go").autocomplete({ source: "search_city.php", select: function (event, ui) { item_val = ui.item.value;

代码:

get-city.php

<script>
    $(document).ready(function() {
        $("#where_to_go").autocomplete({
            source: "search_city.php",
            select: function (event, ui) 
            {
                item_val =  ui.item.value;
                $.ajax({
                    type:"POST",
                    data:{"item_val":item_val},
                    url:"get-city.php",
                    success:function(data){
                        //alert(data);
                        ("#hotel_name").html(data);
                    }
                });
                return false;
            }
        });
    });
</script>
在这段代码中,我有一个自动完成文本框,它可以正常工作。当我从自动完成中选择任何值并使用alertdata时,该值是alert的,但使用$hotel\u name.htmldata时,它在选择框中不显示任何内容。我不知道为什么?那么,我如何解决这个问题?请帮帮我


谢谢

您的代码是否在选择框中追加数据?请检查并在您的问题中添加ajax响应。使用$beforhotel_name.htmldataOhh不,对不起,我忘了$thanx@CananauCristian现在可以使用了。
<?php 
include("dbase.php");
    $item_val = $_POST['item_val'];
?>
<select name="hotel_name" id="hotel_name">
    <option value="">Select Hotel</option>
    <?php
        $sql = "select hotel_name from hotel where city = '".$item_val."' or state = '".$item_val."'";
        $result = mysqli_query($con,$sql);
        while($row = mysqli_fetch_array($result))
        {
            echo "<option value='".$row['hotel_name']."'>".$row['hotel_name']."</option>";
        }
    ?>
</select>