Я пытаюсь реализовать этот учебник в моем приложении.Мне удалось заставить его работать до тех пор, пока мне не пришлось изменить контроллер представления и добавить ссылку на файл .ajax.html.
Пока мой код:
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;
}
}
Файл add-recipe.ajax.phtml:
<?php
foreach ($this->words as $word) {
echo "{$word}\n";
}
?>
Файл вида 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" />
По какой-то странной причине, если я заменю $('#username').autocompleteArray('http://bucatarie/menu/add-recipe/format/html');
на $('#username').autocompleteArray(['Jack', 'John', 'Jason', 'Jeremy', 'jimmy', 'jean']);
это работает отлично.Кажется, я не понимаю, в чем проблема.