我可以得到mapUrl 使用函数fecthData。但它无法显示地图。如果我评论了警报行代码,它将显示地图。任何人都可以给我一些提示吗?提前致谢。
dojo.require("esri.map");
var mapLayer;
var mapUrl;
function init() {
// use ajax to get map url
fecthData("MapInfo?id=1", function (d) {mapUrl = d.mapUrl;});
map = new esri.Map("map");
// if um-commented below line, the map will show
//alert("mapUrl"+mapUrl);
// map layer
mapLayer = new esri.layers.ArcGISDynamicMapServiceLayer(mapUrl);
if ( mapLayer == undefined )
return;
dojo.connect(mapLayer, "onLoad", initFunc);
map.addLayer(mapLayer);
}
function fecthData(varUrl, varFunc) {
var options = {
type: "POST",
url: varUrl,
data: "",
contentType: "application/json;charset=utf-8",
dataType: "json",
cache: false,
success: varFunc
};
//execute the ajax call and get a response
var request = $.ajax(options);
}
dojo.addOnLoad(init);