0

I am having difficulty while handling multiple XHR request fired using esri/request.

I am firing multiple request using code below

var def1 = esriRequest({
   url: url1,
   content: { f: "json" },
   handleAs: "json",
   callbackParamName: "callback"
});


var def2 = esriRequest({
    url: url2,
    content: { f: "json" },
    handleAs: "json",
    callbackParamName: "callback"
});

To handle this I am writing following code

var promise1 = def1.promise;
var promise2 = def2.promise;

all(promise1, promise2).then(function (results) {
    console.log(results);//here I am getting results as deferred instead of actual result. why?
}, function (err) {
    console.log(err);
});

I am getting results as deferred in the success callback of all above.

Can someone please tell me why I am getting deferred instead of actual results?

Amit Dube
  • 947
  • 4
  • 10
  • 23

1 Answers1

0

I was getting results as deferred because I was missing square brackets in the parameters passed to all. The correct way to call all is as follows

var promise1 = def1.promise;
var promise2 = def2.promise;

all([promise1, promise2]).then(function (results) {
   console.log(results);
}, function (err) {
   console.log(err);
});
Amit Dube
  • 947
  • 4
  • 10
  • 23