I am having a ajax post call to a cakePhp Controller:
$.ajax({
type: \"POST\",
url: \'locations/add\',
data: {
In the latest version of CakePHP $this->response->type()
and $this->response->body()
are deprecated.
Instead you should use $this->response->withType()
and $this->response->withStringBody()
E.g:
(this was pinched from the accepted answer)
if ($this->request->is('post')) {
$location = $this->Locations->patchEntity($location, $this->request->data);
if ($this->Locations->save($location)) {
//$this->Flash->success(__('The location has been saved.'));
//return $this->redirect(['action' => 'index']);
$resultJ = json_encode(array('result' => 'success'));
$this->response = $this->response
->withType('application/json') // Here
->withStringBody($resultJ) // and here
return $this->response;
}
}
Relevant Documentation