I am pulling marker objects off of database using the folowing standard XHR request
//retrieve markerData from JSON
function retrieveMarkers(){
var markersXMLhttp = new XMLHttpRequest();
//open the request and store parameters for the request. GET (or POST) is method to send,
//the pathway or url of the data is specified, and whether or not the request is asynchronous
markersXMLhttp.open("GET", "../../map/json/myMapMarker.json", false);
//send the request
markersXMLhttp.send();
//there conditions allow the request to wait until the server respondes that it is ready.
if(markersXMLhttp.readyState == 4 && markersXMLhttp.status == 200){
//the response is stored in a variable
var XMLmarkersResult = markersXMLhttp.responseText;
}
//convert JSON string to javascript object
var markersResult = JSON.parse(XMLmarkersResult);
return markersResult;
}
I have Asynchronous set to false and so I get the following error
Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user’s experience.
I agree Mozilla! So lets change my Asynch to true. O snap, now I get this error.
SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data
What the hell is going on, my JSON file isnt any different. Does asynchronous handle json differently? Id love to resolve this to the point where I am not getting any errors on my request. Following I will post a sample of my JSON code in case the problem lies there.
{
"myMarkers" : [
{
"index" : "000",
"position" : {
"lat" : 45.5,
"lng" : -122.61
},
"description" : "Portland OR",
"infoWindow" : "The origin of the journey, where my roots are, and were many great people live"
},
{
"index" : "001",
"position" : {
"lat" : 44.5,
"lng" : -121.61
},
"description" : "A New Place",
"infoWindow" : "The duplicat will carry for the replicons... until the safe find the fires of the fury"
}
]
}