CakePHP 2.1 + AJAX Search / JsHelper



我尝试使用 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 ;?>

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

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

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

最新更新