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 Achievement module


The Achievement module has the same flow as other modules. We make another Ajax call to ajax_handler.php to build this module. Notice that in the callback function from the Ajax call, a data is written in JavaScript Object Notation (JSON). We need to loop this JSON object to actually access the achievement data. We also need to dynamically build an HTML table that will hold the achievement images. Finally, we append the HTML that we have constructed to the MyAchievements div:

function GetMyAchievements(){
  var action='GetMyAchievements',
  player=getFromLocalStorage('player'),
  html="<table style=\"margin:0 auto;\">";
  $.ajax({
        dataType: "json",
        data: {action:action,player:player},
        url: $AJAXHANDLER,
        success: function (data) {
    var Achievements = data[0].BadgesEarned.split(',');
    for (var i = 0; i < Achievements.length; i++) { 
    AchievementId=Achievements[i];
    html+='<tr>';
    html+='<td><a href...
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