(thinkphp、jQuery)ajax返回json数据
生活随笔
收集整理的這篇文章主要介紹了
(thinkphp、jQuery)ajax返回json数据
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
Thinkphp部分代碼:
<?php namespace Yxg\Controller;use Think\Controller;class IndexController extends Controller{public function index(){$SongName = D('Song');//數(shù)據(jù)查詢$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>結(jié)果返回json數(shù)據(jù):
效果圖:
?
轉(zhuǎn)載于:https://www.cnblogs.com/softwarecrash/p/9300004.html
總結(jié)
以上是生活随笔為你收集整理的(thinkphp、jQuery)ajax返回json数据的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
