0
我有两个功能如何让函数initMap()在它的执行之间等待?
function otherfun(val){
var data = {'latitude': val[0], 'longitude': val[1]};
$.post(URL, data, function(response){
if(response){
// I want to return response from here
}
else{ alert('Error! :('); }
});
}
function initMap() {
var pos = {};
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
var pos = {
lat: position.coords.latitude,
lng: position.coords.longitude
};
var output = otherfun([pos.lat,pos.lng]);
alert(output);
// use output's value further
}
功能initMap()执行最初。我传递的纬度和经度值来otherfun()
我想:
- 返回的从功能otherfun响应的价值。
- 使initMap()函数等待otherfun()的返回并存储在变量输出中
- 然后显示带有输出值的警报框。