我在 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();
?>
但是,按下按钮时不会提交表单。
我将感谢任何帮助!
Thanks!
在您的视图文件中尝试以下操作:
<?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();
?>
NOTE: #CommentSaveForm
是由 CakePHP 生成的 ID,如果您有自己的 ID,则使用它
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)