var hhhhhhh = '';
function displayLocation(latitude, longitude) {
var request = new XMLHttpRequest();
var method = 'GET';
var url = 'http://maps.googleapis.com/maps/api/geocode/json?latlng=' + latitude + ',' + longitude + '&sensor=true';
var async = true;
request.open(method, url, async);
request.onreadystatechange = function() {
if (request.readyState == 4 && request.status == 200) {
var data = JSON.parse(request.responseText);
var addressComponents = data.results[0].address_components;
for (i = 3; i < 4; i++) {
hhhhhhh = addressComponents[i].long_name;
}
}
};
request.send();
}
console.log(hhhhhhh);
var hhhhhhh没有从displayLocation函数中获取任何值。在控制台中,在函数内部函数之外,它的值为null。请Help.thank你jQuery全局变量值超出功能
'的console.log(hhhhhhh形式)'是正确的后'VAR hhhhhhh形式执行= ''' 。您必须调用该函数,然后输出变量的值 – Roxoradev