【发布时间】:2013-03-06 21:00:41
【问题描述】:
我正在尝试在 cakephp 2.3 中使用 ajax 添加到数据库,但不知道如何设置响应,而是向用户提供我会使用的其他数据
$this->set()
对于普通请求 查看文件:
echo $this->Form->create(); echo $this->Form->input('name');
echo $this->Form->input('email');
echo $this->Form->input('phone');
echo $this->Form->input('message');
echo $this->Js->submit('Send Enquiry', array(
'before' => $this->Js->get('#sending')->effect('fadeIn'),
'success' => $this->Js->get('#sending')->effect('fadeOut'),
'update' => '#success',
'async' => true
));echo $this->Form->end();?>
控制器功能是:
public function add() {
if ($this->request->is('post')) {
$this->Contact->create();
if ($this->Contact->save($this->request->data)) {
if($this->request->isAjax()){
$this->autoRender = false;
echo 'successful';
}else{
$this->Session->setFlash(__('The contact has been saved'));
$this->redirect(array('action' => 'index'));
}
} else {
$this->Session->setFlash(__('The contact could not be saved. Please, try again.'));
}
}
}
【问题讨论】:
-
“不知道如何设置响应,而是向用户提供我本来会使用的其他数据” - 很难说出这里问的是什么。你可以尝试重新措辞吗?
标签: php jquery ajax cakephp cakephp-2.3