thinkphp中ajaxReturn方法实现ajax效果
前台代码:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> <load href='__PUBLIC__/js/jquery-2.1.4.min.js'/> <script> $(function(){ $('input[name="button"]').click(function(){ $.get('__URL__/getAjax',function(jdata){ if (jdata.status==1) { $('div#ajax').html(jdata.data); } }); }); }); </script> </head> <body> <div id='ajax' style='width:500px;height:100px;background:yellow'></div> <input type="button" name='button' value='点击'> </body> </html>
php代码:
public function getAjax(){ $data=array( 'data'=>'这是我要的数据', 'info'=>'信息', 'status'=>1 ); $this->ajaxReturn($data); }
效果图: