Layui之Ajax轮询查看支付通知
不多说,上完整代码!
<!DOCTYPE html>
<html lang="zh-CN">
<head>
//这里是应有的css文件引用
<?php require "app/admin/view/layout/header.html" ?>
</head>
<body>
<div class="layui-card-body text-center" style="box-sizing: border-box;">
<div id="qrcode" class="layui-inline"></div>
<h2 style="color: red;padding-top:20px">请使用微信扫码支付</h2>
</div>
//这里是应有的js文件引用
<?php require "app/admin/view/layout/footer.html" ?>
<script>
layui.use(['form', 'QRCode'], function () {
var $ = layui.jquery;
var form = layui.form;
var QRCode = layui.QRCode;
new QRCode(document.getElementById("qrcode"), {
text: '二维码的短地址',
width: 250,
height: 250,
colorDark: '#000000',
colorLight: '#ffffff',
correctLevel: QRCode.CorrectLevel.H,
});
//1.支付轮询
$(document).ready(function () {
setInterval(function () {
//1.先得到当前iframe层的索引 关闭窗口
var index = parent.layer.getFrameIndex(window.name);
$.post("后台url",
{out_trade_no: "订单号"},
function (res) {
if (res.code === 200) {
layer.msg(res.msg, {icon: 1, time: 2500, shade: 0.4}, function () {
parent.layer.close(index); //2.再执行关闭自身
parent.location.reload();
});
}
}, 'json');
return false;
}, 3000);
});
});
</script>
</body>
</html>