javascript - GeoJson "Not Well Formed" message in console, and appears undefined -
ive included end of script below, i'm trying put json file website using ajax callback function. when inspect page, i'm seeing json file not formed , can't seem find answer. webpage showing json file "undefined." suggestions appreciated!
function debugcallback(response){ var mydata; $("#mydiv").append('geojson data: ' + json.stringify(mydata)); }; function debugajax(){ var mydata; $.ajax("data/megacities.geojson", { datatype: "json", success: function(response){ //mydata = response; debugcallback(mydata); } }); $("#mydiv").append('<br>geojson data:<br>' + json.stringify(mydata)); }; //$("#mydiv").append('geojson data: ' + json.stringify(mydata)); if(typeof mydata === 'undefined') { console.log("undefined data") } else { console.log("not undefined") } $(document).ready(debugajax());
avoid defining several functions , try using this:
$(document).ready(function(){ $.ajax("data/megacities.geojson", { datatype: "json", success: function(response){ $("#mydiv").append('<br>geojson data:<br>' + json.stringify(response)); } }); });
note after response/data ajax call, proceed formatting json.
Comments
Post a Comment