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

Two implementation methods for ThinkPHP to return JSON through AJAX

藏色散人
Release: 2020-12-28 16:11:33
forward
2588 people have browsed it

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');
Copy after login

JS part of the code is as follows:

The code is as follows:

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

Method 2:

The code is as follows:

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

JS part of the code is as follows:

The code is as follows:

alert(d.pic);
Copy after login

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!

Related labels:
source:jb51.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template