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>
document.write(new Date());
</body>
</html>