首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >当我从数据库加载法文文本时,可数据返回无效的json响应。

当我从数据库加载法文文本时,可数据返回无效的json响应。
EN

Stack Overflow用户
提问于 2016-12-02 10:15:41
回答 1查看 1.1K关注 0票数 1

只有当我选择一个包含法语内容的列时,我才会得到这个错误。这可能是语言问题。我能做些什么来避免这个错误?

DataTables警告: id=example表-无效的id=example响应。有关此错误的更多信息,请参见http://datatables.net/tn/1

代码语言:javascript
复制
$(document).ready(function() {
    $('#example').DataTable({
        "processing": true,
        "serverSide": true,
        /*"contentType": false,*/
        "ajax": '<?=base_url()?>'+"posts/get_html_posts"
    });
});
代码语言:javascript
复制
<table id="example" class=" ui table" cellspacing="0" width="100%">
    <thead>
        <tr>
            <th>No</th>
            <th>Category Name</th>
            <th>Subcategoty Name</th>
            <th>Title En</th>
            <th>Title Fr</th>
            <th>Is Draft</th>
            <th>Edit</th>
            <th>Delete</th>
            <th>Website url</th>
        </tr>
    </thead>
</table>

控制器

代码语言:javascript
复制
public function get_html_posts()
    {
        require(APPPATH .'third_party/ssp.class.php' );
        $table = 'posts';
        $primaryKey = 'post_id';
        $columns = array(
            array('db' => 'post_id','dt' => 0),
            array( 'db' => 'category_id', 'dt' => 1 ),
            array( 'db' => 'subcategory_id',  'dt' => 2 ),
            array('db'=>'title_en','dt'=>3),
            array('db'=>'title_fr','dt'=>4),
            array('db' => 'is_draft','dt' => 5,"formatter"=>function($d,$row) {
                if($row['is_draft']==1)
                return "<spna class='ui orange label'>Draft</span>";
                else
                return "<spna class='ui green label'>Published</span>";
            }),
            array('db' => 'post_id','dt'=>6,"formatter"=>function($d,$row) {
                return "<a href='".base_url()."posts/edit/".$row['post_id']."' class='ui orange button padding-10'><i class='write icon margin-0'></i></a>";
            }),

            array('db'=>'post_id','dt'=>7,"formatter"=>function($d,$row) {
                return "<a href='#' class='ui red button padding-10' onclick='return delete_record(this.id)' id='".$row['post_id']."'><i class='remove icon margin-0'></i></a>";
            }),
            array('db'=>'post_slug','dt'=>8,"formatter"=>function($d,$row)
            {
                $web_url = "http://localhost";
                return "<a class='ui orange button padding-10' target='_blank' href=".$web_url.'category/'.str_replace('-','', $row['category_id']).'/'.$row['subcategory_id'].'/'.$row['post_id'].'/'.$row['post_slug']."><i class='expand icon margin-0'></i></a>";
            })

        );

        $sql_details = array(
            'user' => 'root',
            'pass' => '',
            'db'   => 'my_demo',
            'host' => 'localhost'
        );
        //header('Content-Type: application/json');
        echo json_encode(
            SSP::simple( $_GET, $sql_details, $table, $primaryKey, $columns )
        );
    }
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-12-02 10:42:52

我也遇到过类似的问题,有时back.Make肯定会得到有效的json响应。这是最好的例子,您可以引用所有jquery数据相关查询。Jquery数据

我的控制器看起来是这样的:

代码语言:javascript
复制
public function inbox()
     {
         $data = array(
                    'receiverEmail' => $this->session->userdata['user_login']['loginEmail'],
            );
        $response = $this->mail_receive->inbox($data);

     $output = array(
                        "iTotalRecords" =>$this->mail_receive->totalRecords($data),
                        "iTotalDisplayRecords" => $this->mail_receive->totalRecords($data),
                         "aaData" => $response,
                );


        header('Content-Type: application/json');
        echo json_encode($output);

     }

这就是我调用ajax的地方

代码语言:javascript
复制
<script>
    $(document).ready(function() {
        var table = $('#inbox').dataTable( {


         "bServerSide": true,
         "sAjaxSource": "<?php echo base_url(); ?>index.php/Inbox_redirect/inbox",
         "bProcessing": true,
        "order": [],
         "bSortable" : true,
          "aaSorting": [[2, 'asc']],
         "sServerMethod": "GET",
         "columns" : [ 
            {"data" : "mailId"},
            {"data" : "mailSender"},
            {"data" : "mailSubject"},
            {"data" : "mailContent"},
            {"data" : "mailSendDate"} ],
        "columnDefs": [
        { 
            "targets": [ 0 ], //first column / numbering column
            "orderable": false, //set not orderable
        },
        ],

    } );
} );


</script>

请张贴更多的代码,以便它更容易帮助你!

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40929735

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档