javascript - 如何在cakephp2.6中将json文件发送到dataTable

标签 javascript php jquery cakephp

我希望为我的表单搜索部署一个数据表,以便使用 php 的 Solarium 客户端从 Apache solr 获取结果,对于每个结果,我将其转换为 JSON 格式,如下所示:在我的操作搜索中:

public function search() {
    if($_POST){
    // get a select query instance
            $query = $client->createSelect()
                   ->setQuery($forsearch )
                   ->addParam('wt','json');
    // this executes the query and returns the result
                $resultset = $client->select($query);

                $this->response->body(json_encode($result));
    }
    }

如何发送 json 文件来查看此函数中的大部分 url:

$('.datatable-ajax-source table').dataTable({
                "processing": true,
               "serverSide": true,
                "ajax": {
                "url": "http://localhost/solr/users/search.json",

            });

我不能使用 $this->autoRender = false;因为我需要从 search.ctp 输入 forsearch 来获取 $resulset

最佳答案

你好,伙计。 在 Controller 函数上,您必须将响应格式化为具有索引“data”的对象,并且该索引必须包含一个包含将由 Datatables 显示的列表的列表,它必须如下所示:

{ 
    data: [
        [field, field, field, field],
        [field, field, field, field]........
    ]
} 

不要忘记 implode() 某些字段,在您的情况下,您必须 implode() 字段“competence_txt”以使其成为字符串。

检查Datatables oficial website了解更多信息。

关于javascript - 如何在cakephp2.6中将json文件发送到dataTable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38795911/

相关文章:

javascript - 数据表标题在 Bootstrap 选项卡中未对齐

除 Math.round() 之外,Javascript 避免使用 0.2 + 0.4 = 0.6000000000000001

php - 为什么 mysql_real_escape_string 不起作用?

php - SQL UNIQUE约束的错误处理?

javascript - 用JS执行php url

javascript - 将 gulp 脚本从 V3 转换为 V4 时出错

javascript - Firestore 的 Firebase Cloud Functions 未触发

PHP CMS 图片上传错误

jQuery每次完成时,触发函数

javascript - 如何让 onclick 仅在 div 上单击两次时才触发