Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Build Gamified Websites with PHP and jQuery

You're reading from   Build Gamified Websites with PHP and jQuery Using gaming principles to make learning more engaging, motivating, and interactive is a growing trend in web development. It's called gamification, and this book is the complete introduction to its theory and practice.

Arrow left icon
Product type Paperback
Published in Sep 2013
Publisher Packt
ISBN-13 9781782168119
Length 124 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Detrick DeBurr Detrick DeBurr
Author Profile Icon Detrick DeBurr
Detrick DeBurr
Arrow right icon
View More author details
Toc

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...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image