Php 无法在控制器中生成数据的html并在下拉列表中显示选择

Php 无法在控制器中生成数据的html并在下拉列表中显示选择,php,jquery,ajax,codeigniter,Php,Jquery,Ajax,Codeigniter,我想在从下拉列表中选择区域后显示餐厅。但是我的代码没有显示餐厅的名称和菜单按钮请告诉我哪里出错了 这是我的视图代码 <div id="restaurant"> </div> 脚本代码 function get_rests(){ var city_id = $('#city_id').val(); var area_id = $("#area_id").val(); $.ajax({

我想在从下拉列表中选择区域后显示餐厅。但是我的代码没有显示餐厅的名称和菜单按钮请告诉我哪里出错了

这是我的视图代码

    <div id="restaurant">


    </div>
脚本代码

 function get_rests(){

        var city_id = $('#city_id').val();
        var area_id = $("#area_id").val();
        $.ajax({
            type: "POST",
            url: "<?=base_url();?>index.php/Bulk_Controller/get_rests",
            data: {cit_id: city_id,areaID: area_id},
            dataType: "text",
            cache:false,
            success:
                function(data){
                    // alert(data);
                    $('#restaurant').html(data);
                }
        });
    }

您没有调用模型函数从DB表中获取数据

public function get_rests()
{

    $cit_id = $this->input->post('cit_id');
    $area = $this->input->post('areaID');
    $where = array('city_id'=>$cit_id,'city_area_id'=>$area);

    $result= $this->your_model->select_record('table_name',$where);
    $html = '

    <div class="container" id="">


        <table align="centre" class="table table-condensed table-striped table-hover no-margin"style="width:70%" id="">

            <thread>

                <tr style="width: 56%;">
                    <th>
                        No.

                    </th>
                    <th style="">
                        Restaurant Names
                    </th>
                </tr>

            </thread>
            <tbody>

            <?php $i=1;foreach($result as $row){
                ?>

                <tr id="<?php echo $row->restaurant_id; ?>" class="res_id">
                    <th style="">
                        <?php echo  $i++; ?>

                    </th>
                    <th style="">
                        <?php echo $row->restaurant_name; ?>




                    </th>

                    <th style="width: 1%" >
                        <a href="<?php echo base_url();?>index.php/BulkRecipe_Controller/bulk_recipe/<?php echo $row->restaurant_id;?>"  class="btn btn-warning" <i class="glyphicon-edit"></i>See Menu</a>

                    </th>
                </tr>
            <?php } ?>

            </tbody>
        </table>
    </div>

    ';
    echo $html;

您是否收到来自ajax的响应?它看起来如何?js代码与php代码在同一个域上。我要求解决任何cors问题。select_记录在何处被调用,并且您在$html字符串中返回的php代码将永远不会被执行。您从Ajax调用中得到什么响应?@hydre在Ajax响应中整个视图代码显示在控制器中编写的响应中。
 function get_rests(){

        var city_id = $('#city_id').val();
        var area_id = $("#area_id").val();
        $.ajax({
            type: "POST",
            url: "<?=base_url();?>index.php/Bulk_Controller/get_rests",
            data: {cit_id: city_id,areaID: area_id},
            dataType: "text",
            cache:false,
            success:
                function(data){
                    // alert(data);
                    $('#restaurant').html(data);
                }
        });
    }
public function get_rests()
{

    $cit_id = $this->input->post('cit_id');
    $area = $this->input->post('areaID');
    $where = array('city_id'=>$cit_id,'city_area_id'=>$area);

    $result= $this->your_model->select_record('table_name',$where);
    $html = '

    <div class="container" id="">


        <table align="centre" class="table table-condensed table-striped table-hover no-margin"style="width:70%" id="">

            <thread>

                <tr style="width: 56%;">
                    <th>
                        No.

                    </th>
                    <th style="">
                        Restaurant Names
                    </th>
                </tr>

            </thread>
            <tbody>

            <?php $i=1;foreach($result as $row){
                ?>

                <tr id="<?php echo $row->restaurant_id; ?>" class="res_id">
                    <th style="">
                        <?php echo  $i++; ?>

                    </th>
                    <th style="">
                        <?php echo $row->restaurant_name; ?>




                    </th>

                    <th style="width: 1%" >
                        <a href="<?php echo base_url();?>index.php/BulkRecipe_Controller/bulk_recipe/<?php echo $row->restaurant_id;?>"  class="btn btn-warning" <i class="glyphicon-edit"></i>See Menu</a>

                    </th>
                </tr>
            <?php } ?>

            </tbody>
        </table>
    </div>

    ';
    echo $html;