I am trying to send a string via AJAX to a PHP file. I have two lottery wheels, each of them has a result (if you press on "spin"). I wish to receive the results and print them to an HTML file. Please see here: http://zeevm.co.il/rollet/
This is the AJAX code that is sending the first wheels result:
function sendwinnertophp(){
var winner = $("#winner").html();
$.ajax({
type: "POST",
url: "getwinner.php",
data: {
"winner": winner
},
cache: false,
success: function(data){
// alert(data);
},
error: function(err){
alert(err);
}
});
}
This is the PHP code that is saving it to the HTML file:
$file = fopen("log.html", "a");
$ip=$_SERVER['REMOTE_ADDR'];
$winner = $_POST['winner'];
//write the data
$time = date("H:i dS F");
fwrite($file, "<b>Time:</b> $time<br/><b>ip:</b> $ip<br/><b>score:</b> $winner<br/><hr/>" );
fclose( $file );
But, I have two wheels that each of them has its own result. I wish to duplicate the Ajax code so it will send the second wheel's result and print it to the HTML file using the PHP.
I have tried adding this after the first function:
function sendwinnertophp222(){
var winner222 = $("#winner222").html();
$.ajax({
type: "POST",
url: "getwinner.php",
data: {
"winner222": winner222
},
cache: false,
success: function(data){
// alert(data);
},
error: function(err){
alert(err);
}
});
}
And this to the PHP file:
$file = fopen("log.html", "a");
$ip=$_SERVER['REMOTE_ADDR'];
$winner = $_POST['winner'];
$winner222 = $_POST['winner222'];
//write the data
$time = date("H:i dS F");
fwrite($file, "<b>Time:</b> $time<br/><b>ip:</b> $ip<br/><b>score:</b> $winner<br/> $winner222<br/><hr/>" );
fclose( $file );
But it doesn't work.
data: { "winner222": winner222 },The value is the one that should be around quotes, not the key.