Select to view content in your preferred language

esriRequest "then" not recognized

1183
3
02-07-2014 08:00 AM
JasonLin
Emerging Contributor
Hi,

I'm trying to follow the esriRequest sample but am stuck when registering its callback functions.

identifyRequest.then(requestSucceeded, requestFailed);


For some reason, I keep getting a type error saying "Object [object object] has no method 'then' ". Am I missing something?


Thanks,
0 Kudos
3 Replies
derekswingley1
Deactivated User
You're missing parentheses and parameters. Would be good to see more of your code but try something like:

identifyRequest(params).then(requestSucceeded, requestFailed);
0 Kudos
JasonLin
Emerging Contributor
Thanks, Derek. Actually, my code snippet is pretty much like the sample code, which initializes esriRequest's parameters in declaration.

        function getStuff() {
          var restURL = "http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer/layers";
          var myRequest = esriRequest({
            url: restURL,
            content: {f: "json"},
            handleAs: "json",
            callbackParamName: 'callback'
          });

          myRequest.then(requestSucceeded, requestFailed); // Problem!

        function requestSucceeded(response, io){
          alert("Success");
        }

        function requestFailed(error, io){      
          alert("Error");
        }


Still puzzled about why it's complaining about 'then'...
0 Kudos
derekswingley1
Deactivated User
Thanks. Can you double-check that you have esriRequest aliased correctly in you require() statement?

Nothing from you code jumps out at me as wrong. It looks similar to one of our samples that does something similar:  https://developers.arcgis.com/javascript/jssamples/data_requestLayerInfo.html
0 Kudos