I can get the mapUrl use function fecthData.
but it cannot show the map.
and if i um-commented the alert line code, it will show the map.
Anyone can give me some tips?
Thanks in advance.
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);
Looks like your “fecthData” gets the response AFTER your “init” execution ends. I guess that you should init your map right after your “fecthData” is completed, like this:
or something like that