Welcome Guest, Not a member yet? Register   Sign In
autocomplete problem
#1

[eluser]Unknown[/eluser]
i have autocomplete in this example in this link

http://www.jamipietila.fi/codeigniter-an...th-jquery/


that does not work

why
#2

[eluser]TheFuzzy0ne[/eluser]
Reported as a duplicate of http://ellislab.com/forums/viewthread/234258/. Please do not reply to this thread.
#3

[eluser]Unknown[/eluser]
this my code
1-control

Code:
class test extends Controller {

function test()
{
  parent::Controller();
}

  public function __construct()
       {
            parent::__construct();
        
       }

function index(){





}
function autocomplete(){



$this->load->view('autocomplete');
}




function suggestions()
{
$this->load->model('autocomplete_model');
$term = $this->input->post('term',TRUE);

if (strlen($term) < 2) break;

$rows = $this->autocomplete_model->GetAutocomplete(array('keyword' => $term));

$json_array = array();
foreach ($rows as $row)
   array_push($json_array, $row->mystring);

echo json_encode($json_array);
}
  
}
2-this view
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
&lt;html &gt;
&lt;head&gt;
&lt;meta http-equiv="Content-Type" c charset=utf-8" /&gt;
&lt;title&gt;Autocomplete example&lt;/title&gt;
&lt;link href="&lt;?php echo base_url();?&gt;css/jquery-ui.css" rel="stylesheet" type="text/css"/&gt;
[removed][removed]
[removed][removed]
[removed]
$(document).ready(function() {
$(function() {
  $( "#autocomplete" ).autocomplete({
   source: function(request, response) {
    $.ajax({ url: "&lt;?php echo site_url('autocomplete/suggestions'); ?&gt;",
    data: { term: $("#autocomplete").val()},
    dataType: "json",
    type: "POST",
    success: function(data){
     response(data);
    }
   });
  },
  minLength: 2
  });
});
});
[removed]
&lt;/head&gt;
&lt;body&gt;
Text: &lt;input type="text" id="autocomplete" /&gt;
&lt;/body&gt;
&lt;/html&gt;

3- this model

Code:
class autocomplete_Model extends CI_Model
{
    function GetAutocomplete($options = array())
    {
     $this->db->select('mystring');
     $this->db->like('mystring', $options['keyword'], 'after');
     $query = $this->db->get('mytable');
  return $query->result();
    }
}




Theme © iAndrew 2016 - Forum software by © MyBB