Home >Backend Development >PHP Tutorial >About ThinkPHP's method of returning JSON through AJAX
This article mainly introduces the two implementation methods of ThinkPHP returning JSON through AJAX, and analyzes the usage of the built-in ajaxReturn function in ThinkPHP. It has certain reference value. Friends in need can refer to it
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 one:
php code is as follows:
$arr = array( 'name'=>$picname, 'pic'=>$pics, 'size'=>$size ); $this->ajaxReturn (json_encode($arr),'JSON');
JS part code is as follows:
var d=eval('('+d+')');//json转成object alert(d.pic);
Method two:
$arr['name']=$picname; $arr['pic']=$pics; $arr['size']=$size; $this->ajaxReturn ($arr,'JSON');
JS Part of the code is as follows:
alert(d.pic);
The above is the entire content of this article. I hope it will be helpful to everyone’s study. For more related content, please pay attention to the PHP Chinese website!
Related recommendations:
ThinkPHP5 framework cache query operation method
Comprehensive analysis of the source code of thinkphp3.2.0 setInc method
php server-side integrated Alipay APP payment method
# #
The above is the detailed content of About ThinkPHP's method of returning JSON through AJAX. For more information, please follow other related articles on the PHP Chinese website!