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.
http://www.bkjia.com/PHPjc/929675.htmlwww.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...