I am trying to POST the data retrieved from the response variable to the post.php page.
However I am getting the following error; Uncaught SyntaxError: Identifier 'socket' has already been declared
I have tried taking the socket connection outside of the foreach however this hasn't helped.
<?php
$xml = file_get_contents("https://explorer.casinocoin.org/ext/getaddress/c4fpX7druW1JfgveFq6e7WabveVkAvW7gj");
$data = json_decode($xml);
foreach($data->last_txs as $value){
?>
<script>
let socket = new WebSocket("wss://ws01.casinocoin.org:4443");
socket.onopen = function(e) {
console.log("[open] Connection established");
console.log("Sending to server");
socket.send(`{"id": 1,"command": "tx","transaction": "<?php echo $value->addresses; ?>"}`);
};
socket.onmessage = function(event) {
var response = event.data;
$.ajax({
type: 'POST',
url: 'post.php',
data: { feedback:response },
success: function(result) {
$('#feedback').html(result);
},
error: function() {
alert('Some error found. Please try again!');
}
});
socket.close();
};
</script>
<?php } ?>
<div id="feedback"></div>