The Scoring module
First, we will take a look at the Scoring module. It consists of JavaScript with an Ajax call to actually get the score data from the database. Here is the code for the JavaScript method:
function GetMyScore(){ var action='GetMyPoints', player=getFromLocalStorage('player'); $("#myscore").html('0'); $.ajax({ dataType: "text", data: {action:action,player:player}, url: $AJAXHANDLER, success: function (data) { $("#myscore").html(data); }, error: function (xhr, status, error) { alert(status + error + xhr.responseText); } }); }
AjaxHandler.php
In the following code, the Ajax method calls ajax_handler.php
, whose job is to accept the Ajax call and call the correct PHP function based on the action parameter passed to it by the Ajax call:
<?php include 'vupoint.php'; ?> <?php if(isset($_GET['player'])){$player=$_GET['player']; } switch ($_GET['action']) { case 'GetMyPoints': GetMyVuPoints...