-
Notifications
You must be signed in to change notification settings - Fork 0
/
jScript.js~
44 lines (40 loc) · 1.24 KB
/
jScript.js~
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
window.onload = main;
function main() {
var jsonData; // will hold the data returned from the ajax request
function getDate() {
var dateTime = new Date();
return (
dateTime.getDate() + "/" +
(dateTime.getMonth()+1) + "/" +
dateTime.getFullYear() + "|" +
dateTime.getHours() + ":" +
dateTime.getMinutes() + ":" +
dateTime.getSeconds()
);
}
document.getElementById("loadJSONButton").onclick = function() {
loadJSON();
}
function loadJSON() {
// create an AJAX request
var xhttp;
if (window.XMLHttpRequest) {
xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
// wait for server/browser processes to complete
if (this.readyState == 4 && this.status == 200) {
console.log("AJAX request successful");
jsonData = xhttp.responseText;
// console.log(jsonData);
} else {
console.log(getDate());
}
}
} else {
alert("This broswer is too outdated to process modern AJAX requests. Please upgrade before proceeding.");
}
// send the AJAX request
xhttp.open("GET", "sampleData.json", true);
xhttp.send();
}
}