javascript - calling ajax function that is outside document.ready -
i trying populate google map. here's of code. why won't ajax request work? works fine when stick in document.ready() anonymous function, want reuse code, need able call it.
$(document).ready(function(){ var map = new google.maps.map(document.getelementbyid('map'), { center: {lat: 49.105, lng: -97.568}, zoom: 4 }); gettornadoes("test", "test", "yes"); }); // tornado json file function gettornadoes (test, test2, test3) {//these not real parameters $.getjson('water_pollutants.php', function(data){ $.each(data.features, function(index, feature){ var longitude = feature.properties.longitude; var latitude = feature.properties.latitude; ...
i error invalidvalueerror: setmap: not instance of map; , not instance of streetviewpanorama. however, don't think issue google maps. i've had similar issues in past when trying refer ajax functions declared outside document.ready().
i use google maps api also, here 1 recommendation:
change
$(document).ready(function(){ var map = new google.maps.map(document.getelementbyid('map'), { center: {lat: 49.105, lng: -97.568}, zoom: 4 });
to:
var map; $(document).ready(function(){ map = new google.maps.map(document.getelementbyid('map'), { center: {lat: 49.105, lng: -97.568}, zoom: 4 });
Comments
Post a Comment