1 2 |
$this->response->body(json_encode($msg)); return $this->response; |
Method2:
1 2 |
$this->set('msg', $msg); $this->set('_serialize', ['msg']); |
//controller action
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
public function test(){ $msg="this is a call"; //method 1 (chose a method) $this->response->body(json_encode($msg)); return $this->response; //method 2 $this->set('msg', $msg); $this->set('_serialize', ['msg']); } //javascript function call in view function delete_all(){ jQuery.ajax({ type:'POST', async: true, cache: false, url:'mycontroller/test.json', success: function(response){ //success console.log(response); }, error: function(response){ console.log(response); } }); } |