如何在发生时从innerHTML存储php变量数据

时间:2017-08-07 16:50:04

标签: php ajax websocket

我有一个websocket脚本,如果有人发送btc,它会在区块链中查找特定地址。如果付款完成,脚本将使用javascript innerHTML输出一条消息。如果发生这种情况,有没有办法运行php脚本?下面的脚本

<script>

                var btcs = new WebSocket("wss:ws.blockchain.info/inv");

                btcs.onopen = function(){
                    btcs.send(JSON.stringify({"op":"addr_sub", "addr":<?php echo json_encode($new_address, JSON_HEX_TAG); ?>}));
                    };
                btcs.onmessage = function(onmsg) {
                    var response = JSON.parse(onmsg.data);
                    var getOuts = response.x.out;
                    var countOuts = getOuts.length;

                    for(i=0; i<countOuts; i++){
                    var outAdd = response.x.out(i).addr;
                    var address = <?php echo json_encode($new_address, JSON_HEX_TAG); ?>;
                    if(outAdd == address){
                        var amount = response.x.out(i).value;
                        var recAmount = amount / 100000000;
                        document.getElementByid("websocket").innerHTML = "Payment recieved: " + recAmount + "BTC <br>;	
                        };
                    };
                };	
                </script>    
<p id="websocket">Monitoring transaction...</p>

0 个答案:

没有答案