简单的ajax请求加php逻辑处理

处理逻辑 html请求页面——>php1——>php2——html显示

php1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45

if (!(defined('IN_IA'))) {
exit('Access Deined');
}

class ExchangeList_EweiShopV2Page extends ComWebPage {

public function main() {
global $_W;
global $_GPC;

$pindex = max(1, intval($_GPC['page']));
$psize = 20;

$whereTotal = "";
$paramTotal = array('uniacid' => $_W['uniacid']);

if(!empty($_GPC['keyword'])){
$whereTotal.= " and (a.nickname like '%".$_GPC['keyword']."%' or a.realname like '%".$_GPC['keyword']."%') ";
}
$total = pdo_fetch('select count(1) as number from ' . tablename('weikang_deposit_refund') .'a left join '.tablename('weikang_deposit').'b on a.deposit_id = b.id where a.uniacid =:uniacid '.$whereTotal, $paramTotal);


if (!(empty($total))) {
$data = pdo_fetchall('select a.id,a.uniacid, a.openid,a.nickname,a.realname,a.deposit_id,a.draw_money,a.draw_status,a.fail_message,a.operate_user,a.deal_time,a.create_time from'
. tablename('weikang_deposit_refund') .'a left join '.tablename('weikang_deposit').'b on a.deposit_id = b.id where a.uniacid =:uniacid '.$whereTotal.' ORDER BY a.id DESC LIMIT ' . (($pindex - 1) * $psize) . ',' . $psize, $paramTotal);
$pager = pagination2($total['number'], $pindex, $psize);
}
include $this->template('share/exchangelist/exchangelist');
}
/**
* 申请通过
*/
public function edit(){
$this->post();
}
/**
* 跳转逻辑判断
*/
public function post(){
require dirname(__FILE__).'/exchangelistpost.php';
}
//dirname(__FILE__)获得当前文件的绝对地址,不包含文件名,只取绝对地址 例:d://.....后面跟.'/exchangelistpost.php'连接这个文件名

}

php2 post处理页面show_json

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<?php

global $_W;
global $_GPC;
$id = intval($_GPC['id']);
$paramTotal = array('uniacid' => $_W['uniacid']);

if (!empty($id)) {
//查询出当前id的申请退款表中的信息
$data = pdo_fetch('select * from ' . tablename(weikang_deposit_refund) . 'where id =' . $id . ' and uniacid =:uniacid ', $paramTotal);
$refundData = pdo_fetchall('select b.status from ' . tablename('weikang_deposit_refund') . 'a left join ' . tablename('ewei_shop_order') . 'b on a.openid = b.openid where a.uniacid=:uniacid and b.order_type =1 and b.status in (0,1,2)', $paramTotal);

if(count($refundData) > 0){
show_json(0,array("id"=>$id,"message"=>"存在未支付订单"));
}

//正在使用的订单是空的,更新申请退款表和押金表中的数据
$refundData = array('deal_time' => date("Y-m-d H:i:s"), 'draw_status' => 1, 'operate_user' => $_W['account']['name']);
$depositData = array('refund_time' => date("Y-m-d H:i:s"), 'refund_id' => $id);
//更新数据
pdo_update('ims_weikang_deposit', $depositData, array('uniacid' => $_W['uniacid'], 'id' => $data['deposit_id']));

pdo_update('ims_weikang_deposit_refund', $refundData, array('uniacid' => $_W['uniacid'], 'id' => $id));

show_json(1,array("id"=>$id,"message"=>"申请成功"));
}

show_json 格式:{"status":1,"result":{"id":1,"message":"\u7533\u8bf7\u6210\u529f","url":"http:\/\/localhost:8080\/"}}

下面会下如何取得json中的数据

html页面

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<tr class="tr_{$item['id']}">
<th>申请状态</th>
...
<th>操作</th>
</tr>
<tr>
<td>
{if $item['draw_status']==0}
正在申请
{elseif $item['draw_status']==1}
处理成功
{elseif $item['draw_status']==2}
审核失败
{elseif $item['draw_status']==3}
打款失败
{elseif $item['draw_status']==4}
用户取消
{/if}
</td>
...
<td style="overflow:visible;position:relative">
<a class=' apply_draw_money' applyid="{$item['id']}"
href="javascript:;" title="通过申请"><i class='fa fa-check'></i> </a>
</td><
</tr>
<script>
//$(document).ready(function(){.... })这个函数是用来取代页面中的window.onload;
$(document).ready(function (){
//bind()方法的主要功能是在向它绑定的对象上面提供一些事件方法的行为。捕捉到操作栏的请求
$(".apply_draw_money").bind("click",function (){
//在页面显示提示框“是否”confirm() 方法用于显示一个带有指定消息和 OK 及取消按钮的对话框。
if(confirm('是否?')){
//ajax请求post,url php1——>php2——>html
$.ajax({type: "POST",url: "{php echo webUrl('share/exchangelist/edit')}&id="+$(this).attr("applyid") ,dataType:"json",success: function(data){
//因为上级的funciton(data),所以用data.status取得json中的status数据
if(data.status == 1){
//同理取得json中的result中的message
alert(data.result.message);
//在html页面中显示“处理成功”的提示框.表单是<td>从0开始
$(".tr_"+data.result.id).find("td").eq(4).html("处理成功");
}
}
});
}
})
});
</script>

show_json(1,array("id"=>$id,"message"=>"申请成功")); //定义json

show_json 格式:{"status":1,"result":{"id":1,"message":"\u7533\u8bf7\u6210\u529f","url":"http:\/\/localhost:8080\/"}}