加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

微信扫码支付模式二支付状态Ajax轮询实例

发布时间:2020-12-16 01:47:50 所属栏目:百科 来源:网络整理
导读:Ajax 轮训支付状态代码: span style="font-size:18px;"script //设置每隔1000毫秒执行一次load() 方法 setInterval(function(){load()},1000); function load(){ var xmlhttp; if (window.XMLHttpRequest){ // code for IE7+,Firefox,Chrome,Opera,Safari x

Ajax 轮训支付状态代码:

<span style="font-size:18px;"><script>
    //设置每隔1000毫秒执行一次load() 方法
    setInterval(function(){load()},1000);
    function load(){
    	var xmlhttp;  
        if (window.XMLHttpRequest){  
            // code for IE7+,Firefox,Chrome,Opera,Safari  
            xmlhttp=new XMLHttpRequest();  
        }else{  
            // code for IE6,IE5  
            xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");  
        }  
        xmlhttp.onreadystatechange=function(){  
            if (xmlhttp.readyState==4 && xmlhttp.status==200){  
            	trade_state=xmlhttp.responseText;
            	if(trade_state=='SUCCESS'){
                	document.getElementById("myDiv").innerHTML='支付成功';
                	document.getElementById('green').style.background="green";
                	//alert(transaction_id);
                	//延迟3000毫秒执行tz() 方法
                	setTimeout(function(){tz()},3000);
                	function tz(){
                		window.location.href="http://www.5188zc.com/index.php?ctl=payment&act=notify&class_name=Pcwxcodepay";
                    }
                }else if(trade_state=='REFUND'){
                	document.getElementById("myDiv").innerHTML='转入退款';
                }else if(trade_state=='NOTPAY'){
                	document.getElementById("myDiv").innerHTML='请扫码支付';
                	
                }else if(trade_state=='CLOSED'){
                	document.getElementById("myDiv").innerHTML='已关闭';
                }else if(trade_state=='REVOKED'){
                	document.getElementById("myDiv").innerHTML='已撤销';
                }else if(trade_state=='USERPAYING'){
                	document.getElementById("myDiv").innerHTML='用户支付中';
                }else if(trade_state=='PAYERROR'){
                	document.getElementById("myDiv").innerHTML='支付失败';
                }
            	
            }  
        }  
        //orderquery.php 文件返回订单状态,通过订单状态确定支付状态
        xmlhttp.open("POST","orderquery.php",true);  
        //下面这句话必须有  
        //把标签/值对添加到要发送的头文件。  
        xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");  
        xmlhttp.send("out_trade_no=<?php echo $payment_notice['notice_sn'];?>"); 
        }
    </script></span>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读