I'm facing an issue while trying to retrieve data for my map using an AJAX call. The error message I receive is:
SyntaxError: JSON.parse: unexpected end of data at line 1 column 1 of the JSON data
. Interestingly, two previous datasets in my application worked fine and were displayed on the screen. However, when I attempted to add a third dataset, this error occurred and the variable dataArray
remains empty.
geojson_popupInfo = {
"type": "FeatureCollection",
"features": [],
};
geojson_dataTable = {
"type": "FeatureCollection",
"features": [],
};
var dataArray = data.split(", ;");
dataArray.pop();
dataArray.forEach(function(d){
d = d.split(", ");
var feature_popupInfo = {
"type": "Feature",
"properties": {},
"geometry": JSON.parse(d[fieldList.length])
};
var feature_dataTable = {
"type": "Feature",
"properties": {},
"geometry": JSON.parse(d[fieldList.length])
};
for (var i=0; i<fieldList.length; i++){
if ([fieldList[i].show_field] == 't') {
feature_popupInfo.properties[fieldList[i].field_alias] = d[i];
}
feature_dataTable.properties[fieldList[i].field_name] = d[i];
};
geojson_popupInfo.features.push(feature_popupInfo);
geojson_dataTable.features.push(feature_dataTable);
});
console.log(dataArray)