Cakephp3: How can I return json data?

前端 未结 8 3052
不思量自难忘°
不思量自难忘° 2021-02-19 09:39

I am having a ajax post call to a cakePhp Controller:

$.ajax({
                type: \"POST\",
                url: \'locations/add\',
                data: {
           


        
8条回答
  •  爱一瞬间的悲伤
    2021-02-19 10:14

    RequestHandler is not required to send json. In controller's action:

    $this->viewBuilder()->setClassName('Json');
    $result = ['result' => $success ? 'success' : 'error'];
    $this->set($result);
    $this->set('_serialize', array_keys($result));
    

提交回复
热议问题