【发布时间】:2015-07-09 20:29:15
【问题描述】:
这是我的 JavaScript 代码:
$('#tags').select2({
tags: true,
tokenSeparators: [','],
createSearchChoice: function (term) {
return {
id: $.trim(term),
text: $.trim(term) + ' (new tag)'
};
},
ajax: {
url: '<?php echo site_url('home_page/get_tags');?>',
dataType: 'json',
data: function(term, page) {
return {
q: term
};
},
results: function(data, page) {
alert(data);
return {
results: data
};
}
},
我的控制器:
public function get_tags()
{
$data= $this->common_model->get_tags_list();
$d = json_encode($data);
echo $d;
}
我得到的 AJAX 响应:
����������[{"tag_id":"1","tag_list":"#follow"},{"tag_id":"2","tag_list":"#all_shots" },{"tag_id":"3","tag_list":"#instago"},{"tag_id":"4","tag_list":"#style"},{"tag_id":"5"," tag_list":"#TFLers"},{"tag_id":"6","tag_list":"#follow"},{"tag_id":"7","tag_list":"#all_shots"},{"tag_id ":"8","tag_list":"#instago"},{"tag_id":"9","tag_list":"#style"},{"tag_id":"10","tag_list":"# TFLers"},{"tag_id":"11","tag_list":"#igers"},{"tag_id":"12","tag_list":"#girl"},{"tag_id":"13" ,"tag_list":"#colorful"},{"tag_id":"14","tag_list":"#nature"},{"tag_id":"15","tag_list":"#tree"},{ "tag_id":"16","tag_list":"#green"},{"tag_id":"17","tag_list":"#skylovers"},{"tag_id":"18","tag_list": "鞋子"},{"tag_id":"19","tag_list":"scaper"}]
我想删除这些字符并仅获取从控制器发送的响应,如下所示:
[{"tag_id":"1","tag_list":"#follow"},{"tag_id":"2","tag_list":"#all_shots"},{"tag_id":"3" ,"tag_list":"#instago"},{"tag_id":"4","tag_list":"#style"},{"tag_id":"5","tag_list":"#TFLers"},{ "tag_id":"6","tag_list":"#follow"},{"tag_id":"7","tag_list":"#all_shots"},{"tag_id":"8","tag_list": "#instago"},{"tag_id":"9","tag_list":"#style"},{"tag_id":"10","tag_list":"#TFLers"},{"tag_id":" 11","tag_list":"#igers"},{"tag_id":"12","tag_list":"#girl"},{"tag_id":"13","tag_list":"#colorful"} ,{"tag_id":"14","tag_list":"#nature"},{"tag_id":"15","tag_list":"#tree"},{"tag_id":"16","tag_list ":"#green"},{"tag_id":"17","tag_list":"#skylovers"},{"tag_id":"18","tag_list":"shoes"},{"tag_id": "19","tag_list":"scaper"}]
【问题讨论】:
-
是否注册了任何 PHP 输出处理程序?
-
猜测是UTF8字节序标记,保存不带字节序标记的文件stackoverflow.com/questions/3255993/…
-
当你
die($d);时你会得到什么 -
@NullPoiиteя 什么都没有,因为 $id 没有定义。
-
对不起,你死后会得到什么($d)?
标签: javascript php ajax json codeigniter