So I'm trying to use a free service to get the visitor's location and redirect them to the proper page. The problem is that these free services don't always work; freegeoip has a limit of 10000 requests per day and I'm not sure about telize.
What I want to do is to load another json if the initial one fails.
To be honest I don't know if it is possible my way. I apreciate any other ideas or scripts, the main idea is just to get the visitor's location and point them to the right page, using javascript. I'm on Blogger, by the way, so not so many options available.
Regards.

<script>
jQuery.ajax({
  dataType: "json",
  url: 'http://www.telize.coom/geoip?callback=?',
  cache: true,
  success: function(location) {
if (location.country_code == 'ID') { 
window.top.location.href = 'http://id.example.com';
}
else if (location.country_code == 'US') { 
window.top.location.href = 'http://en.example.com';
}
},
error: function(location) {
jQuery.getJSON('http://freegeoip.net/json/', function(location) {
if (location.country_code == 'ID') { 
window.top.location.href = 'http://id.example.com';
}
else if (location.country_code == 'US') { 
window.top.location.href = 'http://en.example.com';
}
})
}
</script>

Recommended Answers

This may not be the answer your looking for but i would fire off both requests and use the first one that responded correctly.

Jump to Post

All 2 Replies

This may not be the answer your looking for but i would fire off both requests and use the first one that responded correctly.

Member Avatar

there is no such thing as an ajax.jquery function

commented: hyepr active +0
commented: gfh +0
Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.