Home  >  Article  >  Backend Development  >  Two implementation methods for ThinkPHP to return JSON through AJAX, thinkphpjson_PHP tutorial

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

WBOY
WBOYOriginal
2016-07-13 10:11:231121browse

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...
Statement:
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