aboutsummaryrefslogtreecommitdiffstats
path: root/js/craftmine.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/craftmine.js')
-rw-r--r--js/craftmine.js22
1 files changed, 17 insertions, 5 deletions
diff --git a/js/craftmine.js b/js/craftmine.js
index bbb1074..66c35fc 100644
--- a/js/craftmine.js
+++ b/js/craftmine.js
@@ -11,7 +11,12 @@ function sendRequest(url, params, callback) {
xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhr.onreadystatechange = function() {
if(xhr.readyState == XMLHttpRequest.DONE && xhr.status == "200") {
- callback(xhr);
+ var data = JSON.parse(xhr.responseText);
+ if(data.error) {
+ showError(data.error);
+ return;
+ }
+ if(callback) callback(data);
}
}
xhr.send(params);
@@ -24,9 +29,14 @@ function updateData() {
}
}
+function debitAccount(amount) {
+ data.gold -= amount;
+ updateData("gold");
+}
+
function withdrawMine() {
sendRequest("craftmine.php", "op=withdrawMine&amount="+data.mine, function(xhr) {
- var gold = parseInt(xhr.responseText); // Server's response is a string
+ var gold = parseInt(xhr); // Server's response is a string
if(isNaN(gold)) return;
data.gold = gold;
data.mine = 0;
@@ -35,9 +45,10 @@ function withdrawMine() {
}
function initCraftMine() {
- sendRequest("craftmine.php", "op=getCraftMine", function(xhr) {
- var ret = xhr.responseText;
- data.gold = parseInt(ret); // Server's response is a string
+ sendRequest("craftmine.php", "op=getCraftMine", function(ret) {
+ data.gold = parseInt(ret.gold); // Server's response is a string
+ if(ret.shop) displayShop(ret.shop);
+ displayInventory(ret.inventory);
updateData("gold");
})
}
@@ -50,5 +61,6 @@ function updateMine() {
function init() {
initCraftMine();
+ changeTab();
window.setInterval(updateMine, 1000);
}