Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var city;
- var endpoint = 'http://ip-api.com/json/?fields=city,country,isp,status,message,countryCode';
- var xhr = new XMLHttpRequest();
- xhr.onreadystatechange = function() {
- if (this.readyState == 4 && this.status == 200) {
- var response = JSON.parse(this.responseText);
- if(response.status !== 'success') {
- console.log('query failed: ' + response.message);
- return
- }
- else{
- city = response.city;
- console.log("test1 " + city); //this is working
- }
- }
- };
- xhr.open('GET', endpoint, true);
- xhr.send();
- console.log("test2 "+ city); //this is not working
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement