CakePHP 2.1 + AJAX Search / JsHelper

时间:2012-05-09 14:40:44

标签: cakephp cakephp-2.0

我尝试使用JsHelper使用CakePHP创建Ajax搜索。 Ajax请求会触发,但它永远不会返回值:

搜索表单(find_entries.ctp):

<?php echo $this->Form->create('Entry');?>
<?php echo $this->Form->input('title', array('div' => false, 'empty', 'label' => false, 'placeholder' => 'Search'));?>

<?php echo $this->Js->submit('Upload', array(
    'before'=>$this->Js->get('#checking')->effect('fadeIn'),
    'success'=>$this->Js->get('#checking')->effect('fadeOut'),
    'update'=>'#choose_options')
    )
;?> 
<?php echo $this->Form->end();?>

控制器:

public function find_entries(){
    if(!empty($this->request->data)){

            $entries = $this->Entry->find('all', array('conditions' => array('Entry.title' => $this->request->data['Entry']['title);    
    $this->set('entries', $entries);
    if($this->RequestHandler->isAjax()){
    $this->render('entries', 'ajax');   
    }
    }

}

部分渲染(entries.ctp)

<div id="entries">

<?php foreach ($entries as $entry) :?>

    <?php echo $entry['Entry']['title']; ?>

<?php endforeach ;?>

这里出了什么问题?谢谢!

1 个答案:

答案 0 :(得分:1)

您是否创建了任何标识为choose_options的div标记来呈现ajax结果?如果没有在视图文件中创建这样的div标签。

<div id="choose_options"></div>