forked from tntp/Tntp.CodingExercise
-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
50 lines (47 loc) · 1.37 KB
/
script.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
45
46
47
48
49
/**
* Created by Aloma on 10/18/2016.
*/
function getXMLHTTPRequest()
{
var request;
// Lets try using ActiveX to instantiate the XMLHttpRequest object
try{
request = new ActiveXObject("Microsoft.XMLHTTP");
}catch(ex1){
try{
request = new ActiveXObject("Msxml2.XMLHTTP");
}catch(ex2){
request = null;
}
}
// If the previous didn't work, lets check if the browser natively support XMLHttpRequest
if(!request && typeof XMLHttpRequest != "undefined"){
//The browser does, so lets instantiate the object
request = new XMLHttpRequest();
}
return request;
}
function loadURL(filename, callback)
{
var aXMLHttpRequest = getXMLHTTPRequest();
var allData;
if (aXMLHttpRequest)
{
aXMLHttpRequest.open("GET", filename, true);
aXMLHttpRequest.onreadystatechange = function (aEvt) {
if(aXMLHttpRequest.readyState == 4){
allData = aXMLHttpRequest.responseText;
if(allData === "noauth"){
alert("Your session has expired. Relogin to continue.")
window.location.reload();
}
callback(allData)
}
};
aXMLHttpRequest.send(null);
}
else
{
alert("A problem occurred instantiating the XMLHttpRequest object.");
}
}