2017-05-30 06:52:58 +00:00
|
|
|
/* AJAX Tutorial, By The Net Ninja
|
|
|
|
https://www.youtube.com/watch?v=h0ZUpPiV1ac
|
|
|
|
*/
|
|
|
|
|
|
|
|
window.onload = function(){
|
|
|
|
|
2017-06-15 06:14:57 +00:00
|
|
|
const serverPath = "https://server.figytuna.com:8080/ali/hello/";
|
2017-06-15 18:29:14 +00:00
|
|
|
const pages = {
|
|
|
|
"unsafe": [
|
|
|
|
"World",
|
|
|
|
"Data",
|
|
|
|
"Post"
|
|
|
|
],
|
|
|
|
"html":[
|
|
|
|
"Location",
|
|
|
|
"Players",
|
|
|
|
]
|
|
|
|
}
|
2017-06-15 06:14:57 +00:00
|
|
|
//Generate HTML table
|
2017-06-15 18:29:14 +00:00
|
|
|
for (const pageType in pages){
|
|
|
|
for (const pagePath of pages[pageType]){
|
|
|
|
//Adds new table row based on the data request
|
|
|
|
const $newTableRow = $("<tr>"
|
|
|
|
+ "<td>Hello " + pagePath + "</td>"
|
|
|
|
+ "<td id=\"hello-"+ pagePath.toLowerCase() + "\"></td>"
|
|
|
|
+ "</tr>");
|
2017-06-15 06:14:57 +00:00
|
|
|
|
2017-06-15 18:29:14 +00:00
|
|
|
console.log(pagePath + " added");
|
|
|
|
//Appends new table row to table
|
|
|
|
$("#hello-table").append($newTableRow);
|
|
|
|
}
|
2017-05-30 06:52:58 +00:00
|
|
|
}
|
|
|
|
|
2017-06-15 18:29:14 +00:00
|
|
|
dataRequest = function(pagePath, pageType, requestType){
|
|
|
|
$.ajax({
|
|
|
|
type: requestType,
|
|
|
|
url: serverPath + pagePath.toLowerCase(),
|
|
|
|
timeout: 2000,
|
|
|
|
beforeSend: function(data){
|
|
|
|
$("#hello-" + pagePath.toLowerCase()).html("<em>Loading...</em>");
|
|
|
|
},
|
|
|
|
success: function(data){
|
|
|
|
$element = $("#hello-" + pagePath.toLowerCase())
|
|
|
|
if (pageType == "html"){
|
|
|
|
$element.html($data);
|
|
|
|
}else{
|
|
|
|
$element.text($data);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
error: function(e){
|
|
|
|
$("#hello-" + pagePath.toLowerCase()).html("<em>Error " + e.status + " " + e.statusText + "</em>");
|
|
|
|
}
|
2017-06-15 06:14:57 +00:00
|
|
|
});
|
|
|
|
}
|
2017-06-15 18:29:14 +00:00
|
|
|
//Gets Table data from server
|
|
|
|
for (const pagePath of pages["html"]){
|
|
|
|
dataRequest(pagePath, "safe", "GET");
|
|
|
|
}
|
|
|
|
|
|
|
|
for (const pagePath of pages["unsafe"]){
|
|
|
|
dataRequest(pagePath, "unsafe", "GET");
|
|
|
|
}
|
2017-05-30 06:52:58 +00:00
|
|
|
}
|