在基于 ajax 的系统中,建议遵循异步开发,这意味着所有需要处理 ajax 调用返回的数据的代码都必须添加到相应的回调方法中
var path_data = path + "?q=map/get_data/" + param1 + '/' + param2 + '/' + param3 + '/' + param4 +'/' + param5;
var path_map_center = path + "?q=map/get_center/" + param1;
$.getJSON(path_map_center, function(data) {
var center_lati = data.lati;
var center_longi = data.longi;
//all code that need to work with center_lati and center_longi should be added here
});
// do no put any ode that need to work with center_lati and center_longi should be added here
不过,如果您不打算使用异步模式,请使用该async
选项
var path_data = path + "?q=map/get_data/" + param1 + '/' + param2 + '/' + param3 + '/' + param4 + '/' + param5;
var path_map_center = path + "?q=map/get_center/" + param1;
$.ajax({
url: path_map_center,
dataType: 'json',
type: 'GET',
async: false,
success: function (data) {
center_lati = data.lati;
center_longi = data.longi;
}
})