Reputation: 9844
I had this piece of code:
$.getJSON("https://nycdatastables.s3.amazonaws.com/2013-08-19T18:22:23.125Z/community-districts-polygon.geojson", function(data)
{
// Add GeoJSON layer to the map once the file is loaded
geojson = L.geoJson(data,
{
style: style,
onEachFeature: onEachFeature
}).addTo(map);
});
Which load some data into a map.
However, I want to keep the information, and since $.getJSON
is asynchronous., I changed it to $.ajax
with the proper parameters:
$.ajax({async: false, url: "https://nycdatastables.s3.amazonaws.com/2013-08-19T18:22:23.125Z/community-districts-polygon.geojson", success: function(data)
{
// Add GeoJSON layer to the map once the file is loaded
geojson = L.geoJson(data,
{
style: style,
onEachFeature: onEachFeature
}).addTo(map);
}});
The first piece of code worked fine. However, since I changed the method I get:
Error: Invalid GeoJSON object.
geometryToLayerleaflet.js:7:18482
addDataleaflet.js:7:17049
initializeleaflet.js:7:16778
eleaflet.js:5:2544
geoJsonleaflet.js:7:20518
successmap.js:38
jjquery-2.1.0.min.js:1:26681
fireWithjquery-2.1.0.min.js:1:27490
xjquery-2.1.0.min.js:3:10523
(anonymous function)jquery-2.1.0.min.js:3:14160
send
sendjquery-2.1.0.min.js:3:14347
ajaxjquery-2.1.0.min.js:3:9975
loadNeighborhoodsmap.js:35
(anonymous function)index.html:106
This just happens with $.ajax
.
Upvotes: 1
Views: 636
Reputation: 42054
jQuery.getJSON() is a shorthand Ajax function, which is equivalent to:
$.ajax({ dataType: "json", url: url, data: data, success: success });
So in your ajax call you forgot the dataType parameter.
Upvotes: 2