File tree Expand file tree Collapse file tree 2 files changed +33
-10
lines changed Expand file tree Collapse file tree 2 files changed +33
-10
lines changed Original file line number Diff line number Diff line change @@ -82,20 +82,25 @@ function getRequest(subUrl = "", params = ""){
8282var jsonData = null ;
8383var data = null ;
8484
85-
8685var XMLHttpRequest = require ( "xmlhttprequest" ) . XMLHttpRequest ;
8786var xhr = new XMLHttpRequest ( ) ;
8887xhr . withCredentials = true ;
8988xhr . addEventListener ( "readystatechange" , function ( ) {
89+
9090if ( this . readyState === 4 ) {
9191
92- jsonData = JSON . parse ( this . responseText ) ;
92+ if ( this . status == 0 ) {
93+ jsonData = {
94+ "message" : "Internet is not connected!"
95+ } ;
96+ } else {
97+ jsonData = JSON . parse ( this . responseText ) ;
98+ }
99+
93100}
94101} ) ;
95- console . log ( "https://api.ipgeolocation.io/" + subUrl + "?" + params + "" ) ;
96102xhr . open ( "GET" , "https://api.ipgeolocation.io/" + subUrl + "?" + params + "" , false ) ;
97103xhr . send ( data ) ;
98-
99104return jsonData ;
100105
101106}
@@ -114,7 +119,13 @@ var xhr = new XMLHttpRequest();
114119xhr . withCredentials = true ;
115120xhr . addEventListener ( "readystatechange" , function ( ) {
116121if ( this . readyState === 4 ) {
117- jsonData = JSON . parse ( this . responseText ) ;
122+ if ( this . status == 0 ) {
123+ jsonData = {
124+ "message" : "Internet is not connected!"
125+ } ;
126+ } else {
127+ jsonData = JSON . parse ( this . responseText ) ;
128+ }
118129}
119130} ) ;
120131xhr . open ( "POST" , "https://api.ipgeolocation.io/" + subUrl + "?apiKey=" + apiKey + "" , false ) ;
Original file line number Diff line number Diff line change 11{
22 "name" : " ip-geolocation-api-javascript-sdk" ,
3- "version" : " 1.0.0 " ,
3+ "version" : " 1.0.3 " ,
44 "description" : " " ,
55 "main" : " IPGeolocationAPI.js" ,
6+ "dependencies" : {
7+ "xmlhttprequest" : " ^1.8.0"
8+ },
69 "scripts" : {
710 "test" : " echo \" Error: no test specified\" && exit 1"
811 },
12+ "keywords" : [
13+ " ip" ,
14+ " ipgeo" ,
15+ " ip geolocation" ,
16+ " ip geolocation api" ,
17+ " time zone" ,
18+ " ip geolocation sdk" ,
19+ " geolocation javascript" ,
20+ " geoip lookup" ,
21+ " geoip api" ,
22+ " ip location api"
23+ ],
924 "author" : " ipgeolocation" ,
10- "license" : " ISC" ,
11- "dependencies" : {
12- "xmlhttprequest" : " ^1.8.0"
13- }
25+ "license" : " ISC"
1426}
You can’t perform that action at this time.
0 commit comments