View Full Version : Off site AJAX exception(s)?!

06-24-2016, 09:42 PM
I would have thought this code was impossible (cross domain security). Yet I found its basics on Stack Overflow and played with it to make something somewhat useful, and damned if it doesn't work:

<!DOCTYPE html>
<title>Current Time in lat/lng from lat/lng Using Google Maps API and jQuery</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<div id="results"></div>
<script type="text/javascript">
function curTimefrmLatLng(lat, lng){
var ts = Math.round(new Date().getTime() / 1000);
var gmre = /[^\d]*$/;
success: function(response){
if(response.timeZoneId != null){
window.console && console.log(response);
ts = ts + response.dstOffset + response.rawOffset;
gm = new Date(ts * 1000).toUTCString().replace(gmre, " " + response.timeZoneName);
$('#results').html('Current time in ' + response.timeZoneId + ' : ' + gm);
curTimefrmLatLng(34.0522, -118.2437); // running with LA's lat/lng



Only impressive if you're not in the pst/pdt timezone.