Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

180
Views
Get response data from outside of esriRequest callback

I am trying to get data from rest service using 'esri/request'. My question is how to get response data from this request and use it outside of this in other function. But do not realize how it's possible under below fromOutSide() without using window variable.

https://developers.arcgis.com/javascript/3/jsapi/esri.request-amd.html

Finally found way to get variables from outside of .then using lang.hitch Code in below one

define([
    'dojo',
    'dojo/_base/declare',
    'jimu/BaseWidget',
    'dojo/_base/array',
    'dojo/_base/lang',
    'esri/request'
],
function(
    dojo,
    declare,
    BaseWidget,
    array,
    lang,
    esriRequest,
) {
    // Run

    this.getMapService;


    getMapService: function() {
        var requestHandle = esriRequest({
            url: "https://services.arcgisonline.com/arcgis/rest/services/World_Topo_Map/MapServer/0?f=pjson",
            content: {
                f: "json"
            },
            handleAs: "json",
            callbackParamName: "callback"
        });
        requestHandle.then(this.requestSucceeded, this.requestFailed);
        
    },

    requestSucceeded: function(response, io) {
        let responseVar = response;
        console.log(responseVar);
    },

    requestFailed: function(error, io) {
        console.log(error);

    },

    fromOutSide: function() {
        // ? ? ? ?
        console.log(myVar);

    }

});




Updated code: After lang.hitch I was able to use my variables inside .then 
=========================================================


define([
    'dojo/_base/lang',
    'esri/request'
  ],
  function (
    lang,
    esriRequest
  ) {
    return declare([BaseWidget], {
      
      getWindDirection: function () {
          this.requestHandleNode.innerHTML = "";
          
          requestArgs = {
          url: this.config.windDirRestUrl,
          content: {
            f: "json"
            },
          handleAs: "json",
          callbackParamName: "callback",
            };
          
          esriRequest(requestArgs).then(lang.hitch(this, function (response) {
                                            this.requestSucceeded(response);
                                        }),
                                        lang.hitch(this, function (error) {
                                            this.requestFailed(error);
                                        })
            );               
      },
      
      requestSucceeded: function (response, io){
          this.showWindDirection(response);

      },
        
      requestFailed: function (error){
          console.log(error);
          
      },
      
      showWindDirection: function (response){
          console.log(response)
            
      }
      
    });
  });
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!