dongruan6001 2017-06-12 12:09
浏览 67

自动填充文本框无效

controller:

<?php
    defined('BASEPATH') OR exit('No direct script access allowed');
    class Test extends CI_Controller 
    {
        function __construct() 
        {
            parent :: __construct();
            $this->load->helper(array('form', 'url'));
            $this->load->model('select');
        }
        public function index()
        {
            $this->load->view('index'); 
            if(isset($_GET['term'])){
            $location = strtolower($_GET['term']);      
            echo $this->select->autoload($college_name);          
            }  
        }
    }

view:

<link rel="stylesheet" type="text/css" href="http://code.jquery.com/ui/1.9.2/themes/base/jquery-ui.css" />
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.3.js"></script>
<script type="text/javascript" src="http://code.jquery.com/ui/1.9.2/jquery-ui.js"></script>
<script type="text/javascript">
        $(document).ready(function() {
            $( "#colleges" ).autocomplete({
                source: function(request, response) {
                    $.ajax({
                        url: "http://localhost/collegescan_ci/index.php/test/search",
                        data: { term: $("#colleges").val()},
                        dataType: "json",
                        type: "POST",
                        success: function(data){
                           var resp = $.map(data,function(obj){
                                return obj.college_name;
                           }); 
                           response(resp);
                        }
                    });
                },
                minLength: 2
            });
        });
    </script>
<input type="text" name="colleges" id="colleges"/>

model:

<?php
  class Select extends CI_Model{
    public function autoload($term)
      {
        $query = $this->db->query("SELECT college_name FROM all_colleges where college_name like '%".$term."%' ORDER BY CASE WHEN short_name LIKE '%".$term."%' THEN 1 ELSE 2 END");
        echo json_encode($query->result_array());
      }
  }

I am new in codeigniter and I want to create an autocomplete textbox. In this code I am created an autocomplete textbox which is not working. I don't know why ? can anybody help me please.

Thank You

  • 写回答

1条回答 默认 最新

  • dsmupo6631 2017-06-12 12:28
    关注

    Please follow the codeigntor manual.As per codeigntor manual the model name should be like this 'Yourmodelname_model' also not sure you can give model name as 'Select',

    class Select_model extends CI_Model{
        function autoload() {
            $row_set = array();
            $this->db->select('*');
            $this->db->like('college_name', $college_name);
            $query = $this->db->get('venue_details');
    
            if (count($query->result_array()) > 0) {
              foreach ($query->result_array() as $row) {
                  $row_set[] = htmlentities(stripslashes($row['college_name']));
              }
    
            }
            return json_encode($row_set);
         }
      }
    

    Please refer codeigntor giude,

    https://www.codeigniter.com/userguide3/general/models.html

    评论

报告相同问题?

悬赏问题

  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能