document ready function var dbUnivers var dbAch var eContent content v

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
$(document).ready(function() {
var dbUnivers = '';
var dbAch = '';
var eContent = $('#content');
var eLoading = $('#loading');
// UI
function HideLoading() {
var block = new $.Deferred();
eLoading.slideUp(1000, function() {
block.resolve();
});
return block.promise();
}
function ShowLoading() {
var hideBlock = new $.Deferred();
eLoading.delay(100).slideDown(1000, function() {
setTimeout(function() {
hideBlock.resolve();
}, 3000);
});
return hideBlock.promise();
}
// AJAX
function GetUniversEx() {
var block = new $.Deferred();
$.ajax({
type: "POST",
url: "../ajax/dbGetUniversEx.php",
data: {
get: 1
},
dataType: "json",
beforeSend: function() {
// nothing
},
success: function(json) {
dbUnivers = json;
},
complete: function() {
block.resolve();
},
error: function() {
block.reject();
}
});
return block.promise();
}
function GetAch() {
var block = new $.Deferred();
$.ajax({
type: "POST",
url: "../ajax/dbGetAch.php",
data: {
get: 1
},
dataType: "json",
beforeSend: function() {
},
success: function(json) {
dbAch = json;
},
complete: function() {
block.resolve();
},
error: function() {
window.location.replace("http://" + window.location.host + "/error.php?type=1014");
}
});
return block.promise();
}
function GetDataWithLoading() {
$.when(ShowLoading(), GetUniversEx(), GetAch())
.done(function() {
$.when(HideLoading().done(function() {
if (!JsonErrorCheck(dbAch) && !JsonErrorCheck(dbUnivers)) {
var select = $("<select></select>");
$.each(dbAch, function(key, value) {
select.append($("<option></option>").prop("value", key).text(value['full']));
});
eContent.append(select);
} else {
eContent.append(HTMLNewErrorDiv('', 'Description', 322));
}
// Show content with animation
eContent.hide().delay(100).slideDown("slow");
}));
})
.fail(function() {
alert("$.get failed!");
});
}
// int main()
GetDataWithLoading();
});