I am trying to access some information based on IP Address and wish to display it in my web page using JavaScript. I am getting my data based on IP address but when I try to do it with JavaScript, I am not getting any error same time no output.
Below I am posting my code. Please give me some valuable information about this and also try to correct my code.
<!DOCTYPE html>
<html>
<head>
<title>JS Get Request</title>
</head>
<body>
<center>JavaScript Get Request Test</center>
statusCode : <p id="statusCode"></p><br/>
stausMessage : <p id="statusMessage"></p><br/>
ipAddress : <p id="ipAddress"></p><br/>
countryCode : <p id="countryCode"></p><br/>
countryName : <p id="countryName"></p><br/>
regionName : <p id="regionName"></p><br/>
cityName : <p id="cityName"></p><br/>
zipCode : <p id="zipCode"></p><br/>
latitude : <p id="latitude"></p><br/>
<script type="text/javascript">
var HttpClient = function(){
this.get = function(aUrl, aCallback){
var anHttpRequest = new XMLHttpRequest();
anHttpRequest.onreadystatechange = function() {
if(anHttpRequest.readyState == 4 && anHttpRequest.status ==200)
aCallback(anHttpRequest.responseText);
}
anHttpRequest.open("GET", aUrl, true);
anHttpRequest.send(null);
}
}
var theurl = 'http://api.ipinfodb.com/v3/ip-city/?key=c7b0a48b0232ec3a0154bac3af7707170dd8268116543d6719262d49724bfc38&ip=106.51.76.69&format=json';
var client = new HttpClient();
client.get(theurl, function(resonse){
var response1 = JSON.parse(response);
//alert(response);
});
document.getElementById("statusCode").innerHTML = response1.statusCode;
document.getElementById("statusMessage").innerHTML = response1.statusMessage;
document.getElementById("ipAddress").innerHTML = response1.ipAddress;
document.getElementById("countryCode").innerHTML = response1.countryCode;
document.getElementById("countryName").innerHTML = response1.countryName;
document.getElementById("regionName").innerHTML = response1.regionName;
document.getElementById("cityName").innerHTML = response1.cityName;
document.getElementById("zipCode").innerHTML = response1.zipCode;
document.getElementById("latitude").innerHTML = response1.latitude;
</script>
</body>
</html>
` does not use a closing slash and never has.