codeigniter ajax返回整个html代码而不是给出div部分

时间:2018-04-23 12:14:32

标签: javascript codeigniter

这是我的ajax代码:

function choosecab(thisvalue){
    var carname =$(thisvalue).data('carname');

    $.ajax({
        type: "POST",
        url: base_url+"welcome/getcab",                         
        data: "carname="+carname, 
        cache: false,
        success: function(html){    
                    console.log(html);          
                $(".right-side-widget").html(html);
                //window.location.href= base_url+"Tariff";  
        }
    });


}   

这是我的控制器:

if($_POST):
        if(isset($_POST) && !empty($_POST)):
            $data = $_POST;             
            $cabfilter=array(
                "carchoosed" =>  $data['carname'],
                "page" => "Tariff/cabfilter",
            );

            $this->session->set_userdata('form2data', $cabfilter);
        $this->load->view('tariff', $cabfilter);    
        endif;
    endif;

cabfilter视图包含以下代码,

             <div class="col-lg-6 col-md-6 inp-align" >
                <div class="row sel-car-row" style="padding:0;">
                   <div class="col-lg-12">
                      <select name="car_id" class="selectpicker tariff-select-picker" required="" data-style="btn-info">
                         <option selected="selected" disabled >Select Members </option>     
                         <option  >2 </option>          
                         <option >4 </option>                                                                                    
                         <option  >6 </option>          
                      </select> 
                    </div>
                </div>    
            </div>

来自ajax调用的响应包括页眉和页脚内容。在这里,我只需要由控制器加载的div部分。我无法猜出代码有什么问题?有人可以帮我解决这个问题吗?

1 个答案:

答案 0 :(得分:0)

更改此

find

$this->load->view('tariff', $cabfilter);