I am trying to implement auto complete functionality in my application. But instead of getting suggestions it is showing java script lines of my code. For example: if I type 'n', then it shows all java script lines having 'n'as a character. I have pasted all the required .js and .css files in their respective folders. I don't where I am lacking. Please help me. I am pasting my controller and view part.
Controller:
public function find_name() {
if ($this->request->is('ajax')) {
$this->autoRender = false;
$panel_name = $this->request->query('term');
$results = $this->Panel->find('all', array(
'conditions' => array('Panel.name LIKE ' => '%' . $panel_name . '%'),
'recursive' => -1
));
$resultArr = array();
foreach($results as $result) {
$resultArr[] = array('label' =>$result['Panel']['name'] , 'value' => $result['Panel']['name'] );
}
echo json_encode($resultArr);
}`
View:
$('.pchange').each(function()
{
var g=$(this).attr('id');
//alert(g);
var lastChar = g.replace ( /[^\d.]/g, '' );
$('#name'+lastChar).autocomplete("PanelsController/find_name",
{
minChars: 1,
delay: 0,
maxCacheLength: 100,
onItemSelect:
function (item)
{
alert(item);
$("#name"+lastChar).val(item.data[0]);
$("#phone"+lastChar).val(item.data[1]);
$("#email"+lastChar).val(item.data[2]);
}
});
});