PHP JSON响应错误的初始引号

时间:2018-03-04 23:06:11

标签: php jquery ajax

我有一个ajax请求示例:

$( "#searchMonitor" ).autocomplete({
    source:baseUrl + "util/searchMonitor",
    focus: function(event, ui) {
        $('input[id="searchMonitor"]').val(ui['item'].label);

        /// needs 'cause we need label and not ID on textbox
        event.preventDefault();
    },
    select: function(event, ui) {
        $('input[name="userId"]').val(ui['item'].value);
        $('input[id="searchMonitor"]').val(ui['item'].label);
        log(ui);
        event.preventDefault();
    }
});

一切正常......请求被发送到服务器,响应是200但有一个问题。

   ''[{"label":"Kevin Kouketsu","value":"1"},{"label":"Kevinkouketssu","value":"46"},{"label":"Kevinkouketssu","value":"47"},{"label":"Kevinkouketssu","value":"48"}]

这''是不正常的,没有发生......

public function searchMonitor() {
    $search = strtolower($this->input->get('term'));

    $user = $this->users->getUserByName($search);
    $row_set = array();
    foreach ($user as $row){
        $new_row['label']=(stripslashes($row['nome']));
        $new_row['value']=htmlentities(stripslashes($row['id']));
        $row_set[] = $new_row; //build an array
    }

    echo json_encode($row_set); //format the array into json data
}

PHP代码...... 并且每个ajax请求都会返回'' ...

0 个答案:

没有答案