当前位置:
首页 >
(thinkphp、jQuery)ajax返回json数据
发布时间:2025/7/25
112
豆豆
生活随笔
收集整理的这篇文章主要介绍了
(thinkphp、jQuery)ajax返回json数据
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
Thinkphp部分代码:
<?php namespace Yxg\Controller;use Think\Controller;class IndexController extends Controller{public function index(){$SongName = D('Song');//数据查询$data = $SongName->where('id=2')->find();//ajax返回if($data){$this->ajaxReturn($data);}else{$data = "ERROR";$this->ajaxReturn($data);}} }jQuery部分:
<!DOCTYPE html> <html> <head><title></title><script src="https://cdn.bootcss.com/jquery/3.3.0/jquery.min.js"></script> </head> <body><div id="div1"></div>><script type="text/javascript">$(document).ready(function(){$.ajax({url: '{:U('Index/index')}',type: 'POST',dataType: 'json',success: function(data){$("#div1").html(data);}});});</script> </body> </html>结果返回json数据:
效果图:
转载于:https://www.cnblogs.com/softwarecrash/p/9300004.html
总结
以上是生活随笔为你收集整理的(thinkphp、jQuery)ajax返回json数据的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: jade过滤器
- 下一篇: Windows下phpStudy中的Ap