Автоматическая подача формы с задержкой в javascript
Привет.
Я должен сделать игру в камень-ножницы-бумага на php, и мне нужно знать, как автоматически отправить свою форму, а также с задержкой.
Ниже я включу все свои файлы, надеюсь, вы сможете мне помочь.
Я искал в Интернете решение, но, похоже, ничего не работает.
Footer.php(Расположение Формы)
<footer class="footer"> <div class="res"> <ul> <li>Player A <br/>Wins <?php echo $wincount; ?></li> <li>Draws: <?php echo $drawcount; ?></li> <li>Player B <br/>Wins <?php echo $losscount; ?></li> </ul> </div> <div class="options"> <form action="" method="post" style="" name="onloadsubmit" id="form"> <input name="submitted" type="hidden" value="1" /> <input id="throwcount" name="throwcount" type="hidden" value="<?php echo $throwcount; ?>" /> <input id="wincount" name="wincount" type="hidden" value="<?php echo $wincount; ?>" /> <input id="losscount" name="losscount" type="hidden" value="<?php echo $losscount; ?>" /> <input id="drawcount" name="drawcount" type="hidden" value="<?php echo $drawcount; ?>" /> <label><input type="submit" name="playerthrow" value="PAPER" id="throw_2"></label> </form> </div> </footer>
Что я уже пробовал:
Proccess.php
<?php //set initial variables $throwcount = 0; $wincount = 0; $losscount = 0; $drawcount = 0; $winlossdraw = "No games played yet"; $playerthrow = "N/A"; $computerthrow = "N/A"; if (isset($_POST['submitted'])==1) { //get variables $throwcount = $_POST['throwcount']; $wincount = $_POST['wincount']; $losscount = $_POST['losscount']; $drawcount = $_POST['drawcount']; $playerthrow = $_POST['playerthrow']; //randomize computer throw $randomcomp = rand(1,3); if ($randomcomp == 1) { $computerthrow = "ROCK";} if ($randomcomp == 2) { $computerthrow = "PAPER";} if ($randomcomp == 3) { $computerthrow = "SCISSORS";} //compare throws if ($computerthrow == $playerthrow) { $drawcount++; } if ($computerthrow == "ROCK" && $playerthrow == "PAPER") { $wincount++; } if ($computerthrow == "PAPER" && $playerthrow == "SCISSORS") { $wincount++; } if ($computerthrow == "SCISSORS" && $playerthrow == "ROCK") { $wincount++; } if ($computerthrow == "SCISSORS" && $playerthrow == "PAPER") { $losscount++; } if ($computerthrow == "PAPER" && $playerthrow == "ROCK") { $losscount++; } if ($computerthrow == "ROCK" && $playerthrow == "SCISSORS") { $losscount++; } $throwcount++; if ($throwcount == 5) { header('refresh:2;url=end.php'); } } else { //set initial variables $throwcount = 0; $wincount = 0; $losscount = 0; $drawcount = 0; $winlossdraw = "No games played yet"; $playerthrow = "N/A"; $computerthrow = "N/A"; } ?>
FormAutoSubmit.js
function SubmitForm() { var playerthrow = $("#throw_2").val(); var throwcount = $("#throwcount").val(); var wincount = $("#wincount").val(); var losscount = $("#losscount").val(); var drawcount = $("#drawcount").val(); $.post("proccess.php", { throwcount: throwcount, wincount: wincount , losscount: losscount , drawcount: drawcount, playerthrow: playerthrow, }, function(data) { alert("Data Loaded: " +data); }); }