Difference between revisions of "MediaWiki:CreatureList.js"

From Virtuverse Wiki
Jump to navigation Jump to search
(Created page with "function drawTable(mobs) { var output = $("#sandbox-output"); var html = "<table class='vvwiki-table'><tr><th>Name</th><th>HP</th><th>Damage</th></tr>"; mobs.forEach(...")
 
Line 23: Line 23:
 
     },
 
     },
 
     error: function(status, exec) {
 
     error: function(status, exec) {
         // TODO error message
+
         $("#sandbox-output").html("Error retrieving mob data!");
 
     }
 
     }
 
   });
 
   });
 
  $('#sandbox-output').html('Sandbox JS loaded!');
 
 
});
 
});

Revision as of 13:21, 6 August 2019

function drawTable(mobs) {
   var output = $("#sandbox-output");
   var html = "<table class='vvwiki-table'><tr><th>Name</th><th>HP</th><th>Damage</th></tr>";
   mobs.forEach(function(mob) {
      var url = "/index.php/Creatures:"+mob["name"];
      html += "<tr>";
      html += "<td><b><a href='"+url+"'>"+mob["name"]+"</a></b></td>";
      html += "<td>"+mob["hp"]+"</td>";
      html += "<td>"+mob["damage"]+"</td>";
      html += "</tr>"
   });
   html += "</table>";
   output.html(html);
}

$(document).ready(function() {
  $.ajax({
     type: "GET",
     dataType: "json",
     url: "/vv-api/get-creatures.php",
     success: function(data) {
        drawTable(data.result);
     },
     error: function(status, exec) {
        $("#sandbox-output").html("Error retrieving mob data!");
     }
  });
});