This article mainly introduces two implementations of Thinkphp to return JSON through Ajax, analyzes the usage of the built-in Ajaxreturn function in thinkphp, and has a certain reference value, the need of friends can refer to the following
The examples in this article describe two implementations of Thinkphp's return of JSON through Ajax. Share to everyone for your reference. Here's how:
Method One:
The PHP code is as follows:
$arr = Array (' name ' = = $picname, ' pic ' = $pics, ' size ' = = $size); $this->ajaxreturn (Json_encode ($arr), ' JSON ' );
The JS section code is as follows:
var d=eval (' (' +d+ ') ');//json turns into Objectalert (d.pic);
Method Two:
$arr [' name ']= $picname; $arr [' pic ']= $pics; $arr [' Size ']= $size; $this->ajaxreturn ($arr, ' JSON ');
The JS section code is as follows:
alert (d.pic);
The above is the whole content of this article, I hope that everyone's learning has helped, more relevant content please pay attention to topic.alibabacloud.com!