I\'ve spent today researching how to save data using an ajax request in cakephp and have got now where, the documentation on the cakephp website seems a bit lacking for this
public function add_project() {
$this->autoRender = false;
$this->layout = 'ajax';
if ($this->RequestHandler->isAjax()) {
$this->Project->set($this->request->data);
$this->request->data['Project']['user_id'] = $this->Session->read('Auth.User.id');
$this->request->data['Project']['created_by'] = $this->Session->read('Auth.User.id');
$this->request->data['Project']['updated_by'] = $this->Session->read('Auth.User.id');
//$this->request->data['Skill']['accept_decline'] = 0;
$this->User->set($this->request->data['Project']);
Configure::write('debug', 0);
if ($this->Project->validates(array('fieldList' => array('project_title', 'show_on', 'summary')))) {
if ($this->Project->save($this->request->data, false)) {
$response['status'] = 'succses';
$response['message'] = 'data sent';
echo json_encode($response);
exit();
} else {
$response['status'] = 'error';
$response['model'] = 'Project';
$response['message'] = 'data not sent';
echo json_encode($response);
exit();
}
} else {
$response['status'] = 'invalid';
$response['model'] = 'Project';
$errors = $this->Project->validationErrors;
$response['errors'] = $errors;
echo json_encode($response);
exit();
}
}
}