I am trying to implement this tutorial in my application. I have managed to make it work until the point where I had to modify the view controller and add the link to the .ajax.html file.
My code so far:
class MenuController extends Zend_Controller_Action {
public function init() {
$this->_helper->ajaxContext()->addActionContext('addRecipe', 'html')->initContext();
parent::init();
}
public function addRecipeAction() {
if ($this->_helper->ajaxContext()->getCurrentContext()) {
$this->view->words = array('leon', 'lionel', 'Lenny', 'Linda', 'Lindy');
}
$recipeForm = new Application_Form_Recipe();
$recipeForm->setMethod('post');
$recipeForm->setAction('/menu/add-recipe');
$this->view->recipeForm = $recipeForm;
}
}
The add-recipe.ajax.phtml file:
<?php
foreach ($this->words as $word) {
echo "{$word}\n";
}
?>
The view file add-recipe.phtml
<?php
echo $this->headLink()->appendStylesheet('/js/jquery/css/jquery.autocomplete.css');
$this->jQuery()->enable();
$this->jQuery()->addJavascriptFile('/js/jquery/js/jquery.autocomplete.js');
?>
<script type="text/javascript">
$(document).ready(function(){
$('#username').autocompleteArray('http://bucatarie/menu/add-recipe/format/html');
});
</script>
<input type="text" name="username" id="username" />
For some strange reason if i replace $('#username').autocompleteArray('http://bucatarie/menu/add-recipe/format/html');
with $('#username').autocompleteArray(['Jack', 'John', 'Jason', 'Jeremy', 'jimmy', 'jean']);
it works perfect. I can't seem to understand what the problem is.