本文实例讲述了ThinkPHP通过AJAX返回JSON的两种实现方法。分享给大家供大家参考。具体方法如下:
方法一:
php代码如下:
$arr = array(
'name'=>$picname,
'pic'=>$pics,
'size'=>$size
);
$this->ajaxReturn (json_encode($arr),'JSON');
JS部分代码如下:
var d=eval('('+d+')');//json转成object
alert(d.pic);
方法二:
$arr['name']=$picname;
$arr['pic']=$pics;
$arr['size']=$size;
$this->ajaxReturn ($arr,'JSON');
JS部分代码如下:
alert(d.pic);
希望本文所述对大家基于ThinkPHP框架的PHP程序设计有所帮助。
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