codeigniter中的ajax自动搜索

时间:2015-07-23 10:20:52

标签: php ajax codeigniter

此代码中的" domhos / view" 是什么意思?这是观点吗?

控制器search.php

public function autocomplete() {
    $search_data = $this->input->post('search_data');
    $query = $this->Model_Domain->get_autocomplete($search_data);

    foreach ($query->result() as $row):
        echo "<li><a href='" . base_url() . "domhos/view/" . $row->id . "'>" . $row->domain_name . "</a></li>";
    endforeach;
}

1 个答案:

答案 0 :(得分:2)

<强>脚本

$ ruby config.rb 
config.rb:2:in `<main>': undefined method `config' for main:Object (NoMethodError)

<强>控制器

    <script type="text/javascript">
    function ajaxSearch() {
        var input_data = $('#search_data').val();
           $.ajax({

                type: "POST",
                url: "<?php echo base_url(); ?>home/autocomplete",
                data: {id2:input_data},
                success: function(data) {
                if (data.length > 0) {
                $('#suggestions').show();
                $('#autoSuggestionsList').addClass('auto_list');
                $('#autoSuggestionsList').html(data);
                    }
                }
            });
    }

  </script> 

查看

         public function autocomplete() 
         {
            $search_data = $this->input->post('id2');
            $client_details= $this->home_model->get_client_search($search_data);

           foreach ($client_details->result() as $row) 
           {
               echo $row->client_name .'</br>' ;

           }

        }

模型

    <div class="something">
    <input name="search_data" id="search_data" type="text" onkeyup="ajaxSearch();">
    <div id="suggestions">
        <div id="autoSuggestionsList">  
        </div>
    </div>