Kik*_*nev 4 jquery cakephp cakephp-2.x
我在cakephp 2中构建ajax表单时遇到了麻烦,自1.3以来显然已经发生了很大的变化.
我正在使用以下代码:
<div id="commentForm">
<div id="commentStatus"></div>
<?php
echo $this->Form->create('Comment', array('action' => 'save', 'default' => false));
echo $this->Form->input('Comment.comments_name');
echo $this->Form->input('Comment.comments_email');
echo $this->Form->input('Comment.comments_text');
echo $this->Js->submit('Save', array('update' => '#commentStatus'));
echo $this->Form->end();
?>
Run Code Online (Sandbox Code Playgroud)
但是,按下按钮时不会提交表格.
我会感谢任何帮助!
谢谢!
the*_*dox 11
在您的视图文件中尝试此操作:
<?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('Comment', array('action' => 'save', 'default' => false));
echo $this->Form->input('Comment.comments_name');
echo $this->Form->input('Comment.comments_email');
echo $this->Form->input('Comment.comments_text');
echo $this->Form->end(__('Submit'));
echo $this->Js->writeBuffer();
?>
Run Code Online (Sandbox Code Playgroud)
注意: #CommentSaveForm是由CakePHP生成的ID,如果您有自己的ID,则使用它