I had jQuery autocomplete working fine with CodeIngiter when inexplicably it completely stopped. When I visit the controller for autocompletion, I still see the correct array - Javascript just does not return JSON data. What makes this weird is that it works fine and then suddenly stops working.
Here is my Javascript:
$( "#clubs-complete" ).autocomplete({ source: function(request, response) { $.ajax({ url: 'http://www.myurl.com/create/autocomplete', data: 'term='+$("#clubs-complete").val(), dataType: "json", type: "POST", success: function(data){ alert(data); response(data); } }); }, minLength: 1 });
Here is my controller:
public function autocomplete() { // Search term from jQuery $term = $this->input->post('term'); $this->db->select('name','address2'); $this->db->from('clubs'); $this->db->like('name', $term); $suggestions = $this->db->get()->result(); if (count($suggestions) > 0) { $data = array(); foreach ($suggestions as $suggestion) { array_push($data, $suggestion->name); } // Return data echo json_encode($data); } }
Does anyone know what is going on? A warning in the javascript function returns nothing, and before it was used. When I visit the URL directly, I still see the full array.
Please help, I will tear my hair.
source share