Code is at the bottom. (if the question is not formulated correctly please tell me)
I want to write to a json file using javascript and PHP to create a multiplayer game of rock paper scissors. I'm very new to coding in js and PHP so I'll try and formulate as well as possible. In the json file there is an empty string, which should be the user's choice. I want my javascript and PHP file to write the user's choice in there but I have no clue on how to do so. If someone is able to help it would be very appreciated.
{
"player1": {
"choice" : ""
},
"player2": {
"choice": ""
}
}
$(function() {
if ($("#rock").click( function()
{
alert('rock clicked'); // make instructions to send to json.
}
));
});
$(function() {
if ($("#paper").click( function()
{
alert('paper clicked');
}
));
});
$(function() {
if ($("#scissor").click( function()
{
alert('scissor clicked');
}
));
});
<?php
$page_title = 'WP21';
$navigation = Array(
'active' => 'Play',
'items' => Array(
'Play' => 'index.php',
'About' => 'about.php'
)
);
include __DIR__ . '/tpl/head.php';
include __DIR__ . '/tpl/body_start.php';
?>
<script type="application/javascript" src="main.js"></script>
<div class="pd-40"></div>
<div class="row">
<div class="col-md-12" id="news_container">
<button id="rock">Rock</button>
<button id="paper">Paper</button>
<button id="scissor">Scissor</button>
</div>
<p id="keuze"></p>
</div>
<?php
include __DIR__ . '/tpl/body_end.php';
?>