Я пытаюсь получить установку автозаполнения Ajax для текстового поля в CakePhp 2.x.CakePhp Ajax Autocomplete
На моем взгляде, у меня есть:
<?php $this->start('script'); ?>
<script type="text/javascript">
$(document).ready(function() {
var options, a;
jQuery(function() {
options = {
serviceUrl: "<?php echo $this->Html->Url(array('Controller' => 'Logs', 'action' => 'autoComplete')); ?>",
minChars: 2,
};
a = $('#LogTimeSpent').autocomplete(options);
});
});
$('#saveCust').click(function() {
alert("Test")
});
</script>
<?php $this->end(); ?>
В моем контроллере у меня есть:
function autoComplete($query) {
if ($this->request->is('ajax'))
{
$suggestions = $this->Customer->find('all', array(
'conditions' => array(
'Customer.fullName LIKE' => '%'.$query.'%'
)
));
return json_encode(array('query' => $query, 'suggestions' => $suggestions));
}
}
Customer.fullName является виртуальным полем, если это влияет на запрос. Firebug в настоящее время дает мне 500 внутренних ошибок сервера.