AnsweredAssumed Answered

How do I use esriRequest in a widget?

Question asked by mathiaskopo on Nov 9, 2015
Latest reply on Nov 10, 2015 by mathiaskopo

Hello, can anyone guide me in a direction on how to use the esriRequest function in a Web Appbuilder Widget?


I have just started using Web AppBuilder Developer Edition. I started with extending the sample widget Demo with a button


<button id="gotoPosition" data-dojo-type="dijit/form/Button" type="button" data-dojo-attach-point="gotoPosition">Go to position</button>

I then extended the onOpen: function() in widget.js to zoom to a position

 onOpen: function(){
  var map =;
  var Long, Lat;
  var LocPoint, point;   
  //Go to position
  on(this.gotoPosition, 'click', lang.hitch(this, function(evt){   
    console.log('gotoPosition 2');;
    Lat = 55;
    Long = 15;
    LocPoint = new Point([Long,Lat]);


From Access data (XML) | ArcGIS API for JavaScript I found out how to use esriRequest and from Using the proxy | Guide | ArcGIS API for JavaScript how to install the proxy and finally putting it all together in one HTML file (esriRequest_xml.html) which works fine.

<!DOCTYPE html>
  <title>XML Content</title>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  <link rel="stylesheet" href="">
  <script src=""></script>
    require(["dojo/dom", "dojo/on", "dojo/dom-class", "dojo/_base/json", "dojox/xml/parser", "esri/config", "esri/request", "dojo/domReady!"], function(dom, on, domClass, dojoJson, xmlParser, esriConfig, esriRequest) {
      console.log('ok') = "/PHP_proxy/proxy.php";
      var url = "url to a xml docement";
      var requestHandle = esriRequest({
        "url": url,
        "handleAs": "xml"
      requestHandle.then(requestSucceeded, requestFailed);
      function requestSucceeded(response, io){
        //do something with the xml data
      function requestFailed(error, io){


I then tried to put the javascript code from esriRequest_xml.html into the onOpen: function()  but this resulted in the error "Uncaught TypeError: Cannot read property 'io' of undefined" Maybe because of wrong scope?, but don't know how to fix this. Can anyone guide me how to get esriRequest to work?