AnsweredAssumed Answered

Consuming web service REST JSON with  esriRequest

Question asked by ARROCAL on Aug 23, 2016

Hello;

 

I want to create a widget   with a function (function _invoqueWS) that retrieves data from a web service REST JSON with  esriRequest.

 

This function must be invoked from other functions of the widget (startup función for example an others).

 

I created the following functions but when I try to return the JSON content variable, the variable in the startup function is undefined or null. I have also tried to initialize a global variable in the function _invoqueWS  and recover the value in function startup , but without results. What am I doing wrong. In the  invoqueWS function the JSON data is correct.

I am using  API  3.17 javascript

Thank you very much, greetings.

 

///////////////////////////////////

startup: function()

{           

//other code

        var resultado= this_ invoqueWS ();

//other code

  }     

 

_invoqueWS: function() {

           var resultado

           var  url_servicio="XXXXX";        

            var layersRequest = esriRequest({ 

            url: url_servicio,

            handleAs: "json", 

           load: function (result)                         

          resultado = result.ElementosEstacionOutput[0].ID_ESTADOS_INST_EXPRESION;

             

            }, 

           error: function (error)

           { 

                  resultado= error;

            }

                               });

                              

                     return resultado                           

       },

Outcomes