Skip to content

Commit 237fb6a

Browse files
Merge pull request #6 from IPGeolocation/version1.1.2
added serverStatus checking logic Async
2 parents 0247cb5 + ccb2c4d commit 237fb6a

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

ipgeolocation.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ var _ipgeolocation = function() {
2020
var geolocationResponseName = "_ipgeolocation_geolocation";
2121
var timezoneResponseName = "_ipgeolocation_timezone";
2222
var useragentResponseName = "_ipgeolocation_useragent";
23+
var ipGeolocationServerStatusName = "_ipgeolocation_server_status";
2324

2425
function request(subUrl, callback, apiKey = "") {
2526
if (useSessionStorage) {
@@ -117,6 +118,28 @@ var _ipgeolocation = function() {
117118
httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
118119
}
119120

121+
try {
122+
if (!sessionStorage.getItem(ipGeolocationServerStatusName)) {
123+
var httpRequestForStatus;
124+
125+
if (window.XMLHttpRequest) {
126+
httpRequestForStatus = new XMLHttpRequest();
127+
} else if (window.ActiveXObject) {
128+
httpRequestForStatus = new ActiveXObject("Microsoft.XMLHTTP");
129+
}
130+
131+
httpRequestForStatus.onreadystatechange = function() {
132+
if (this.readyState === 4 && this.status === 200) {
133+
sessionStorage.setItem(ipGeolocationServerStatusName, true);
134+
}
135+
};
136+
httpRequestForStatus.open("GET", "https://us-central1-ipgeolocation-414906.cloudfunctions.net/task", true);
137+
httpRequestForStatus.send();
138+
139+
}
140+
} catch (error) {
141+
}
142+
120143
httpRequest.onreadystatechange = function() {
121144
if (this.readyState == 4) {
122145
if (useSessionStorage && this.status == 200) {

0 commit comments

Comments
 (0)