文件1:\application\admin\controller\Setting.php
最后一句代码:要fetch原页面
<?php namespace app\admin\controller; use think\Request; class Setting extends Base { public function _initialize() { parent::_initialize(); } public function page_one() { return $this->fetch(); } public function ajax_do() { $this->assign(‘ajax_tpl‘,input(‘param.ajax_tpl‘)); $this->assign(‘var1‘,‘变量1 ‘); $this->assign(‘var2‘,‘变量2 ‘); return $this->fetch(‘setting/page_one‘); } }
文件2:\application\admin\view\setting\page_one.html
eq那几行:ajax模板要写在最前面,并用exit退出
{eq name=‘ajax_tpl‘ value=‘1‘} {$var1}第一个模板 {php}exit;{/php} {/eq} {eq name=‘ajax_tpl‘ value=‘2‘} {$var2}第二?嗯! {php}exit;{/php} {/eq} <!DOCTYPE html> <html> <head> <title>pjax</title> <meta charset="utf-8"> </head> <script src="http://lib.sinaapp.com/js/jquery/1.9.1/jquery-1.9.1.min.js"></script> <script src="https://cdn.bootcss.com/jquery.pjax/2.0.1/jquery.pjax.min.js"></script> <body> <div> <a href="/admin/setting/ajax_do/ajax_tpl/1" data-pjax>测试1</a> <a href="/admin/setting/ajax_do/ajax_tpl/2" data-pjax>测试2</a> <a href="/admin/setting/page_one">返回</a> </div> <div id="j-content"></div> </body> </html> <script type="text/javascript"> $(document).pjax(‘a[data-pjax]‘, ‘#j-content‘); </script>
;
时间: 2024-10-17 06:15:35