Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

181
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda