Two implementation methods for ThinkPHP to return JSON through AJAX, thinkphpjson_PHP tutorial

WBOY
Release: 2016-07-13 10:11:23
Original
1136 people have browsed it

Two implementation methods for ThinkPHP to return JSON through AJAX, thinkphpjson

The examples in this article describe two implementation methods for ThinkPHP to return JSON through AJAX. Share it with everyone for your reference. The specific method is as follows:

Method 1:
The php code is as follows:

Copy code The code is as follows:
$arr = array(
'name'=>$picname,
'pic'=>$pics,
'size'=>$size
);
$this->ajaxReturn (json_encode($arr),'JSON');

Part of the JS code is as follows:
Copy code The code is as follows:
var d=eval('('+d+')');//convert json to object
alert(d.pic);

Method 2:

Copy code The code is as follows:
$arr['name']=$picname;
$arr['pic']=$pics;
$arr['size']=$size;
$this->ajaxReturn ($arr,'JSON');

Part of the JS code is as follows:
Copy code The code is as follows:
alert(d.pic);

I hope this article will be helpful to everyone’s PHP programming based on the ThinkPHP framework.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/929675.htmlTechArticleTwo implementation methods for ThinkPHP to return JSON through AJAX, thinkphpjson This article describes two methods for ThinkPHP to return JSON through AJAX. Implementation method. Share it with everyone for your reference. Specific methods...
Related labels:
source:php.cn
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!