I am using this script: https://jsfiddle.net/b7wjj39p/1/
I am trying to save the data that is coming after "the winner is:" (after pressing on "spin") to a text file on the server.
I have tried to use this way of saving it:
<?php
$myfile = fopen("myfile.txt", "w");
$txt = "my name
";
fwrite($myfile, $txt);
$txt = "my name
";
fwrite($myfile, $txt);
fclose($myfile);
?>
but I was unable to figure out no how to send the parameters to the server side, and from there to the text file.
First let us see how to get the value. It seems the value is stored in the variable "text". So after the wheel has stopped, the StopRotateWheel function runs. I added an 'alert(text)` after the wheel stops and as you can see the variable is isolated.
function stopRotateWheel () {
clearTimeout(spinTimeout);
var degrees = startAngle * 180 / Math.PI + 90;
var arcd = arc * 180 / Math.PI;
var index = Math.floor((360 - degrees % 360) / arcd);
ctx.save();
ctx.font = params.resultTextFont;
var text = pplArray[index];
$(params.winnerDiv).html(text).show();
alert(text);
ctx.fillText(text, 250 - ctx.measureText(text).width / 2, 250 + 10); // this is showing the text
ctx.restore();
}
Instead of alerting it, you can add it to a hidden input field. Let us call that field "winner" :
$("#winner").val(text)
Then you can send this value to PHP using a simple POST using ajax/jquery like this:
function sendwinnertophp(){
var winner = $("#winner").val();
$.ajax({
type: "POST",
url: "getwinner.php",
data: {winner:winner},
dataType: 'json',
cache: false,
})
.success(function(response) {
alert("winner sent to php!");
});
}