drti52047 2016-05-07 15:53
浏览 48

SyntaxError:JSON.parse:JSON数据第1行第1列的意外字符(Php Codigniter和Jquery)

I am trying to implement jQuery Autocomplete in my Codeigniter project, but I get the Following error in Firefox.

SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data

JavaScript

jQuery("#search").autocomplete({
    source: function(req, response) {
        $.ajax({
            url: "<?php echo site_url('C_systemUser/search_value'); ?>",
            dataType: "text",
            success: function(data) {
                var re = $.ui.autocomplete.escapeRegex(req.term);
                var matcher = new RegExp("^" + re, "i");
                response($.grep(data, function(item) {
                    return matcher.test(item.label);
                }));
            }
        });
    },
    minLength: 2,
    select: function(event, ui) {
        event.preventDefault();
        $('#search').val(ui.item.label);
        $('#id').val(ui.item.value);
    }
});

Modal

function systemUserSearch($q) {
    $this - > db - > select('systemUserID,systemUserName');
    $this - > db - > like('systemUserName', $q);
    $query = $this - > db - > get('systemuser');
    if ($query - > num_rows() > 0) {
        foreach($query - > result_array() as $row) {
            $result_row['label'] = htmlentities(stripslashes($row['systemUserName']));
            $result_row['value'] = htmlentities(stripslashes($row['systemUserID']));
            $result[] = $result_row;
        }
        echo json_encode($result);
    }
}

Control

public function search_value()
{
    $q=$this->input->get('query');
    $this->load->model('m_autocomplete');
    $this->m_autocomplete->systemUserSearch($q);
}
  • 写回答

4条回答 默认 最新

  • doushizhou4477 2016-05-07 16:00
    关注

    Are you sure about this :

        url: "<?php echo site_url('C_systemUser/search_value'); ?>",
    

    Are you well render js in php file ?

    评论

报告相同问题?

悬赏问题

  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比