Updating state and zipcode based on the IP address
I have a field where user inputs Zip code. Based on the value entered I want to populate city and state. How i can do this in开发者_高级运维 jQuery?
You can use Google's Map / Geocoding API, here is a quick demo:
<script src="http://www.google.com/jsapi" type="text/javascript"></script>
<script type="text/javascript">
alert(google.loader.ClientLocation.address.city);
</script>
http://jsfiddle.net/zwPvs/1/
edit: Since the user is communicating directly with Google's servers, you don't even have to pass in an IP address, they figure it out. They may even use some additional points of data beyond IP address, but not sure.
精彩评论