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