亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

哪位大哥能幫我寫個原生的 JS getJSON

哪位大哥能幫我寫個原生的 JS getJSON

智慧大石 2018-07-17 17:26:01
哪位大哥能幫我寫個原生的 JS getJSON,在此感謝了。不是異步請求,請求地址:get2.php?uuid=sssssss失敗返回的JSON {"error_code": 0, "reason": "success", "resultcode": 200, "qr_code": null}點擊按鈕后執行一秒輪詢一次get2.php?uuid=sssssss每輪詢一次,按鈕上的標題顯示次數。輪詢35秒后qr_code還是null,就讓用戶點擊刷新頁面。直到qr_code 欄里是URL 并執行跳轉到該地址。
查看完整描述

1 回答

?
慕萊塢森

TA貢獻1810條經驗 獲得超4個贊

<input type="button" id="but" value="開始" onclick="run(1);" />
<script type="text/javascript">
function run(n) {
    var xhr = new XMLHttpRequest();
    xhr.open('get','get2.php?uuid=sssssss&time='+new Date().getTime());
    xhr.onreadystatechange = function () {
        if (xhr.readyState==4 &&xhr.status==200) {
            document.getElementById("but").value = n;
            var data = JSON.parse(xhr.responseText);
            if (data.qr_code!=null) {
                location.href = data.qr_code;
            } else if (n<35) {
                setTimeout(function(){
                    run(n+1);
                }, 1000);
            } else {
                alert("刷新頁面");
                location.reload();
            }
        }
    }
    xhr.send();
}
</script>


查看完整回答
反對 回復 2018-07-24
  • 1 回答
  • 0 關注
  • 808 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號