I am struggling to get json object outside XMLHttpRequest.This is what I did:
var ohl_json=[];
var req = new XMLHttpRequest();
req.responseType = 'json';
req.open('GET', 'https://raw.githubusercontent.com/tekija/LCd/master/testSO.json', true);
req.onload = function() {
var jsonResponse = req.response;
ohl_json.push(jsonResponse)
};
req.send();
console.log(ohl_json)
I get following output:
Array []
0: Object { type: "FeatureCollection", features: (960) […] }
features: Array(960) [ {…}, {…}, {…}, … ]
type: "FeatureCollection"
<prototype>: Object { … }
length: 1
<prototype>: Array []
I tried to reference it with ohl_json[0] or ohl_json.features but no success. How can I access it?
Any help is appreciated.