Reputation: 869
So I'm relatively new to Javascript and I am having an issue with retrieving JSON data that it is being called twice. Specifically, the getData function grabs JSON data and then retrieves the JSON object and execute the plotMarkers function (I'm working with Google Maps API). In checking the console, the callback function runs twice, which means the list items are appended twice. How can I fix this?
Specific code segment:
function initialize() {
geocoder = new google.maps.Geocoder();
var myOptions = {
zoom: 10,
center: new google.maps.LatLng(-37.811748, 144.962886),
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
getData();
}
function getData() {
jQuery.ajax({
url: 'https://dl.dropboxusercontent.com/u/9546194/gigs.json',
dataType: 'json',
success: function(results) {
plotMarkers(results.gigs);
}
});
}
Any help would be much appreciated!
Upvotes: 0
Views: 1576
Reputation: 94309
Get rid of onload="initialize()"
in body
.
Both google.maps.event.addDomListener(window, 'load', initialize);
and <body onload="initialize()"
are calling initialize
.
Upvotes: 4