Home > Backend Development > PHP Tutorial > About ThinkPHP's method of returning JSON through AJAX

About ThinkPHP's method of returning JSON through AJAX

不言
Release: 2023-04-02 09:38:01
Original
2582 people have browsed it

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');
Copy after login

JS part code is as follows:

var d=eval('('+d+')');//json转成object
alert(d.pic);
Copy after login

Method two:

$arr['name']=$picname;
$arr['pic']=$pics;
$arr['size']=$size;
$this->ajaxReturn ($arr,'JSON');
Copy after login

JS Part of the code is as follows:

alert(d.pic);
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template