I am trying to use the jquery autocomplete widget with codeigniter and keep getting an Internal Server error 500. Here is the code I am using:
View:
<html>
<head></head>
<body>
<input type="text" id="customer_name"/>
<script>
$(document).on('ready', function(){
$("#customer_name").autocomplete({
source: "<?=base_url('customer/customerLookup')?>"
});
});
</script>
</body>
</html>
Controller:
<?php
class customer extends CI_Controller {
public function customerInfo() {
$this->load->view('header');
$this->load->view('customer_view');
$this->load->view('footer');
}
function customerLookup()
{
$q = strtolower( $this->input->get('term'));
$this->customer_model->get_customers($q);
}
}
Model:
class customer_model extends CI_MODEL {
function get_customers($q)
{
$this->db->select('customer_name');
$this->db->like('customer_name', $q);
$query = $this->db->get('customers');
if($query->num_rows() > 0)
{
foreach ($query->result_array() as $row)
{
$row_set[] = htmlentities(stripslashes($row['customer_name'])); //build an array
}
return json_encode($row_set); //format the array into json data
}
}
}
I have read through many forums and tried changing the 'enable_query_string' to TRUE also have tried 'uri_protocol'.
Theses are my current CSRF setting:
$config['csrf_protection'] = FALSE;
$config['csrf_token_name'] = 'csrf_test_name';
$config['csrf_cookie_name'] = 'csrf_cookie_name';
$config['csrf_expire'] = 7200;
$config['csrf_regenerate'] = TRUE;
$config['csrf_exclude_uris'] = array();
I continue to get the Internal server error and cannot figure out why. Help would be much appreciated.
extends CI_Model& the first letter of your model filename & class definition should be capitalizedecho $this->customer_model->get_customers($q);in controller.