我正在尝试通过ajax调用提交表单。
echo $this->Form->create('Bid', array('url' => array(
'controller' => 'bids',
'action' => 'bidProject',
$this->Session->read('employee.Id'),
$pid[0] // project id
),
)
);
echo $this->Form->input('day', array('id' => 'day', 'class' => 'form-control', 'label' => 'Days')) . "</br>";
echo $this->Js->submit(__('Submit', array('before' => $this->Js->get('#sending')->effect('fadeIn'),
'success' => $this->Js->get('#sending')->effect('fadeOut')
)), array('class' => 'btn btn-primary')
);
echo $this->Form->end();
}
这是我在“BidsController”
中的行动bidPorject public function bidProject($eid, $pid) {
$bid = $this->Bid->findByProjectIdAndEmployeeId($pid, $eid);
if (!$bid) {
$this->request->data['Bid']['project_id'] = $pid;
$this->request->data['Bid']['employee_id'] = $eid;
$this->Bid->create();
if ($this->Bid->save($this->request->data)) {
if ($this->request->is('ajax')) {
//Ajax call
}
//$this->Session->setFlash(__('The Bid has been saved'));
}
} else {
$this->Session->setFlash(__('Bid have already done for given Employee Id'));
}
}
当我点击提交按钮时,既没有收到错误也没有请求正在响应,并且数据无法存储在数据库中。我在哪里遇到问题?如何解决这个问题?
答案 0 :(得分:1)
在所有$this-> script ();
之后或提交按钮之后,在任一布局中使用此代码。
$this->Js->writeBuffer(array('inline' => true,'cache' => true))