I am preparing a POC to use IMDB auto complete. I am facing a strange issue. When I enter any keyword, the controller doesn't get call. Here is snippets of javascript and the controller.
index.html
<script type="text/javascript">
$(function(){
$("#q").focus();
$("#q").autocomplete({
minLength: 0,
delay:5,
source: "suggest",
focus: function( event, ui ) {
$(this).val( ui.item.value );
return false;
},
select: function( event, ui ) {
$(this).val( ui.item.value );
return false;
}
}).data("uiAutocomplete")._renderItem = function( ul, item ) {
//code to render autocomplete list
};
});
</script>
application/controller/suggest.php
<?php
$term = trim(strtolower($_REQUEST['term']));
echo $term;
?>
My url is /movies/index.php/suggest?term=g
Would anyone please guide me how to fix this?
Try returning a json string from php:
$arr = array(
0 => array(
'label' => 'item 001',
'value' => 1
),
1 => array(
'label' => 'item 002',
'value' => 2
),
2 => array(
'label' => 'item 003',
'value' => 3
),
);
echo json_encode($arr);
in source just give proper path for suggest controller by adding base_url define a global variable in javascript in base_url before calling script
<script>
var base_url = "<?=base_url()?>";
</script>
source: base_url+"suggest",