TP框架下 $this->ajaxReturn()只能返回不含中文的数据,否则会乱码。
所以在TP框架下返回中文数据只能使用原生PHPjson返回方法。如:
$arr = array('code'=>1,'data'=>$data,'msg'=>'success');
json_encode($arr,JSON_UNESCAPED_UNICODE);
但是按照以上方法返回的数据,类型是一个一json格式书写的字符串。
所以我们需要在前面加一行header。
增加后整体代码为:
header('Content-Type:application/json; charset=utf-8');
$arr = array('code'=>1,'data'=>$data,'msg'=>'success');
json_encode($arr,JSON_UNESCAPED_UNICODE);