On my application, I have a JavaScript cycle that updates tag contents on my page regularly:
<script type="text/javascript">
var players = [];
players.push($('#p0'));
players.push($('#p1'));
players.push($('#p2'));
players.push($('#p3'));
i=0;
/*
* cycle through the players.
*/
function cyclePlayer() {
players[i].parents(".card-header").addClass('border-success');
players[i].load('play.php?p='+i);
i = ++i % players.length;
$('#deck').load('play.php?deck=1');
$('#pile').load('play.php?pile=1');
$('#feedback').load('play.php?feedback=1');
}
PlayerLoop = setInterval('cyclePlayer()', 1500 );
$("#stop").click(function(){
clearInterval(PlayerLoop);
});
$('#reset').click(function() {
$('#deck').load('play.php?reset=1');
location.reload();
});
</script>
The server code that is being called looks like this:
<?php
require '../vendor/autoload.php';
session_start();
use Svc\Myapp\FrontHandler;
$myApp = new FrontHandler();
if (isset($_GET['p']) && !isset($_SESSION['winner'])) {
echo $myApp->playerTurn();
}
if (isset($_GET['deck'])) {
echo $myApp->deckUpdate();
}
if (isset($_GET['pile'])) {
echo $myApp->pileUpdate();
}
if (isset($_GET['feedback'])) {
echo $myApp->feedbackUpdate();
}
Is this production quality code? Is there a way to refactor it to improve it?
<?php
tag never closes, I would say no. \$\endgroup\$var
,const
orlet
. They should start with a lowercase character.PlayerLoop = setInterval('cyclePlayer()', 1500 );
is a nono. Define it withvar
orlet
like thislet playerLoop = setInterval('cyclePlayer()', 1500 );
. \$\endgroup\$