0
我想在cakephp 2.3中使用ajax添加數據庫,但不知道如何設置響應,但用戶使用附加數據會使用如何在cakephp 2.3中返回一個ajax請求響應(數據)給客戶端2.3
$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.'));
}
}
}
「不知道如何設置響應,但與額外的數據,我會使用的用戶」 - 這是很難說什麼被要求在這裏。你可以嘗試重新措詞嗎? – 2013-03-06 21:19:59