Cakephp3: How can I return json data?

前端 未结 8 3018
不思量自难忘°
不思量自难忘° 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:04

    Though I'm not a CakePHP Guru, in my case i'm using cake > 4 and I need some results by ajax call. For this, from my controller i wrote,

    echo json_encode(Dashboard::recentDealers()); die;

    and in my JS file i just need to parse the data using

    JSON.parse(data)

    The ajax call like

     $.get('/recent-dealers', function (data, status) {
       console.log (JSON.parse(data)); });
    });
    

提交回复
热议问题