0

我对 CakePhp 还是很陌生,所以如果我遗漏了什么,请告诉我。我正在尝试创建一个使用 ajax 回发到控制器的表单。这是我所拥有的:

模型:EventExampleModel

class EventExampleModel extends AppModel {

}

查看:/app/View/EventExample/index.ctp

<?php

$data = $this->Js->get('#CommentSaveForm')->serializeForm(array('isForm' => true, 'inline' => true));
$this->Js->get('#CommentSaveForm')->event(
    'submit',
    $this->Js->request(
        array('action' => 'save'),
        array(
            'update' => '#commentStatus',
            'data' => $data,
            'async' => true,
            'dataExpression'=>true,
            'method' => 'POST'
        )
    )
);
echo $this->Form->create('Commenter', array('action' => 'save', 'default' => false));
echo $this->Form->input('Commenter.comments_name');
echo $this->Form->input('Commenter.comments_text');
echo $this->Form->end(__('Submit'));
echo $this->Js->writeBuffer();

?>

<div id="contactStatus">


</div>

控制器:事件示例控制器:

class EventExampleController extends Controller {
  public $helpers = array('Html', 'Form');
    public function index() {
        $this->layout = 'homePage';
    }
    public function save() {

        if ($this->request->is('ajax')) {
            $this->render('contact-ajax-response', 'ajax');
        }
    }
}

和我的布局:

<?php
$cakeDescription = __d('cake_dev', 'Employee Database');
?>
<!DOCTYPE html>
<html>
<head>

    <title>
        <?php echo $cakeDescription ?>
    </title>
    <?php
    echo $this->Html->meta('icon');
    echo $this->Html->css('styles');
    echo $this->fetch('meta');
    echo $this->fetch('script');
    echo $this->Html->script('jquery-1.10.2.js'); // Include jQuery library
    echo $this->Html->script('myScripts');
    ?>
</head>
<body>
<div class="homepage-container">
    <div id="content">
        <?php echo $this->fetch('content'); ?>
    </div>
    <div id="footer">

    </div>
</div>
</body>
</html>

我也有位于 app/webroot/js 文件夹中的 jquery 库。

问题是当页面呈现并且我单击提交按钮时,没有任何反应。我在页面或控制台中没有看到任何错误,并且页面没有回发。我错过了什么?我希望页面异步回发到服务器,并且我的保存函数应该被调用(断点永远不会被击中)。

任何人都可以帮忙吗?

4

1 回答 1

1

您的型号名称错误

正确的约定是

EventExample extends AppModel

和文件名 EventExample.php

只是一个提示。

在谷歌浏览器中打开你的萤火虫或同等产品并检查网络标签。请检查单击按钮时是否触发了某些内容。

于 2013-10-24T23:37:25.820 回答