Ajax调用在浏览器中无法正常工作

时间:2018-02-05 08:37:20

标签: jquery ajax cakephp-3.x

这是显示表格中所有客户列表的代码。目前我只想将其加载到视图页面。

//controller code

public function disp(){
    if( $this->request->is('ajax') ) {
        $this->autoRender = false;
    }
    if ($this->request->isPost()) {
        // get values here 
        $customers = $this->Customers->find('all');
        echo json_encode($customers);
    }
}


//index code in the view

$(document).ready(function() {
     $('#example').DataTable( {
         ajax: {
             'type' : 'post',
             'url': '/disp',
             'dataType': 'json',
         },
     });
});

//routes

$routes->connect('/disp', ['controller' => 'Customers', 'action' => 'disp']);

Ajax调用在浏览器中失败。请告诉我如何将它连接到控制器中的函数并在视图页面中以json格式返回结果?

0 个答案:

没有答案
相关问题