0

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>

Edited by Dani: Not a fully working code snippet; Changed to discussion thread

3
Contributors
2
Replies
11
Views
3 Years
Discussion Span
Last Post by [NOPE]FOREVER
0

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

3

there is no such thing as an ajax.jquery function

Votes + Comments
gfh
hyepr active
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.