AnsweredAssumed Answered

esri.request - wait till response

Question asked by amarsden on Mar 10, 2017
Latest reply on Mar 13, 2017 by amarsden



I have an awful web app that is mainly legacy code I wrote many years back, but functions and the users use it all the time


WE're moving stuff around and at the moment the desktops are at a different site to the data so I'm hitting latency issues.


I have this code


            //return the layer descriptions and © text into arrays - we use this later for the info dialog to generate hyperlinks and © text
            dojo.forEach(dynamicMapServiceLayer.layerInfos, function (layer) {
                var requestHandle = esri.request({
                    url: mapservice2 + "/" + + "?f=json",
                    handleAs: "json",
                    load: function (data) {
                        LayerAttach[] = data.hasAttachments;
                        LayerDescriptions[] = data.description;
                        dynamicMapServiceLayer.layerInfos[].copyrightText = data.copyrightText;
                }, { useProxy: true });


Which I have on the Onload event of the main dynamic map  It reads extra stuff from the rest data of the service that I use to create hyperlinks (as good old ArcIMS did) 


All worked fine until this latency hit.  I have a sub-site that on start up takes a feature passed in the URL, finds the extent of that feature, then passes that into a ID task on the main service.  The output uses the arrays/data produced in the above routine.  With the latency I am getting results of the ID task back before I get all the info from the above code.


I have vague knowledge of defers and the like so surely I should add to each loop above a wait until the data is back until stepping forward, or a wait until everything is back


Any advice welcomed.


In the short term I've given those users who use this sub-site Chrome, which can handle things faster and not get caught up.