1
好吧,这是我的JS功能:异步调用
function GetLatLong() {
var geocoder = new google.maps.Geocoder();
var address = $('#txtAddress').val() + ', ' + $('#txtCity').val() + ', ' + $find('drpState').get_text() + ', ' + $find('drpCountry').get_text();
var result = false;
geocoder.geocode({ 'address': address }, function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
var location = results[0].geometry.location;
$('#hiddenLatLong').val(location);
result = true;
}
else {
alert("Geocode was not successful for the following reason: " + status);
result = true;
}
});
return result;
}
现在,我想是的,我想一旦我存储在隐藏字段中的值返回结果。这里发生的是,我在按钮单击时调用此函数,但因为调用是异步的,所以它在click上返回false,并且我无法在隐藏字段中获得结果值。有没有什么方法可以让我等待或在隐藏领域获得一些解决办法?