I have this code, and for some reason my $.post function fires twice in quick succession (for 'journal/weather') according to Firebug. It still does this when I remove the "if (navigator.geolocation)", however, if I replace the $.post block with something like console.log('test'), it only fires once.
What's even weirder is when I place console.log('test') before the $.post function, then my event only fires once as well. I am assuming something is going on strange with jQuery. Anybody have any ideas?
if (navigator.geolocation)
{
navigator.geolocation.getCurrentPosition(function(position)
{
$.post('journal/weather', {latitude: position.coords.latitude, longitude: position.coords.longitude}, function(result)
{
if (typeof(result.current.temp) != 'undefined')
{
global.temperature = parseInt(result.current.temp, 10);
global.temperature_slider.slider('value', global.temperature);
}
}, "json");
});
}
EDIT: Okay, stranger still, sometimes it fires twice, sometimes once. How can the same piece of code give different results each time it is executed?
EDIT 2: After some experimentation, I think this is a bug in Firefox. Why? Because it happens not only with my page, but others. If I keep refreshing my page, roughly the first 10 times the navigator.geolocation.getCurrentPosition fires the callback function. However, at a point, it quits doing so. And once it reaches this point, it doesn't work for any other website that uses getCurrentPosition. And this problem never happens on Chrome or even IE. Searching Google, I found this:
http://groups.google.com/group/mozilla.feedback.firefox/browse_thread/thread/fecc3fb0bad6d0b8