A good suggestion too.
var ajax = function(url, requestType, callback, queryString) {
var ids = ['MSXML2.XMLHTTP.3.0',
'MSXML2.XMLHTTP',
'Microsoft.XMLHTTP'],
xhr;
if (window.XMLHttpRequest)
xhr = new XMLHttpRequest();
else {
for (var i = 0; i < ids.length; i++) {
try {
xhr = new ActiveXObject(ids[i]);
break;
} catch(e) {}
}
};
xhr.onreadystatechange = function() {
if(xhr.readyState== 4){
if(xhr.status==200)
callback(xhr);
}
};
xhr.open(requestType, url, true);
if (requestType.toUpperCase() === 'GET')
xhr.send();
else if (requestType.toUpperCase() === 'POST')
xhr.send(queryString);
};
ajax("http://maps.googleapis.com/maps/api/geocode/json?latlng=-12.9945,-38.5266&sensor=false","GET",function(xhr){
var ResultJSON = JSON.parse(xhr.response);
console.log(ResultJSON);
});
None of the answers answers your question?
– durtto