Home >PHP Framework >ThinkPHP >Two implementation methods for ThinkPHP to return JSON through AJAX

Two implementation methods for ThinkPHP to return JSON through AJAX

藏色散人
藏色散人forward
2020-12-28 16:11:102580browse

The following tutorial column will introduce to you two implementation methods of ThinkPHP returning JSON through AJAX. I hope it will be helpful to friends in need!

Method 1: Two implementation methods for ThinkPHP to return JSON through AJAX

The php code is as follows:

The code is as follows:

$arr = array(
'name'=>$picname,
'pic'=>$pics,
'size'=>$size
);
$this->ajaxReturn (json_encode($arr),'JSON');

JS part of the code is as follows:

The code is as follows:

var d=eval('('+d+')');//json转成object
alert(d.pic);

Method 2:

The code is as follows:

$arr['name']=$picname;
$arr['pic']=$pics;
$arr['size']=$size;
$this->ajaxReturn ($arr,'JSON');

JS part of the code is as follows:

The code is as follows:

alert(d.pic);

The above is the detailed content of Two implementation methods for ThinkPHP to return JSON through AJAX. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:jb51.net. If there is any infringement, please contact admin@php.cn delete