ThinkPHP页面跳转、Ajax技巧详细介绍(十八)

ThinkPHP页面跳转、Ajax技巧详细介绍


一、页面跳转

$this->success('查询成功',U('User/test')); 
├─//跳当前模块方法下:
├─ $this->success('查询成功','test');
└─//跳到 指定跳转模块方法下
this->success('查询成功',U('User/test')); 
$this->error('查询失败,3秒后跳会之前的页面/上一页');

重定向到New模块的Category操作
$this->redirect('New/category','',5,'页面跳转中...');


二、Ajax技巧
status 操作状态 
info 提示信息 
data 返回数据 
$this->ajaxReturn(返回数据,提示信息,操作状态);

使用例子
模块:IndexAction.class.php
<?php
// ajax的使用
class IndexAction extends Action {
public function index(){
$this->display();
}
public function getAjax(){
//传的值可以是表里面查出来的数据啊。。。。
$this->ajaxReturn('乐杨俊给你Ajax返回的数据信息撒','信息1',1);
}

}
?>
对应index.html页面
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>Index</title>
<script src="__PUBLIC__/Js/jquery.js"></script>
<script>
$(function(){
$('button').bind('click',function(){
$.get('__URL__/getAjax',function(jdata){
   //把值打印出来看看
                                alert(JSON.stringify(jdata));
if(jdata.status==1){
$('div#did').html(jdata.data);
}
});
});
});
</script>
</head>
<body>
<div style='height:50px;background:yellow' id='did'></div>
<button>ajax点击动态获取数据</button>
<script>
document.write(new Date());
</script>
</body>
</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值