AnsweredAssumed Answered

Can   xmlhttprequest and queryTask be used  in promise.all together?

Question asked by gisfinder on Oct 23, 2018
Latest reply on Oct 23, 2018 by rscheitlin

I have two async requests:

  1. ordinary rest request 
  2.  request arcigs map service using queryTask

Can "dojo/promise/all" support the promise.all to process the response after the above two responses returned? 

The above two rest services are all accessible for internet users.

 

My code is as below what I want.

 

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
</head>
<body>
<script src="https://js.arcgis.com/3.26/"></script>
<script>
    require(['dojo/Deferred', 'dojo/promise/all',"esri/request", "esri/config", "esri/tasks/QueryTask","esri/tasks/query"], function(Deferred, all,esriRequest,esriConfig,QueryTask,Query) {
        // code to initate query tasks here
        var qURL = "https://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer/5";
        var queryTask  = new QueryTask(qURL); // ESRI query task
        var query  = new Query();
        query.returnGeometry = false;
        query.where = "STATE_NAME='California'";
        query.outFields = ["*"];
        var xhr = new XMLHttpRequest();  //xhr
        xhr.responseType = "json";
        var url = 'https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/1.0_day.geojson';
    
        var deferredTask2=new Deferred();
        var deferredTask1 = new Deferred();
   xhr.open('GET',url,true);
        xhr.onload=function(e) {
            if(xhr.readyState== 4) {
                deferredTask2.resolve(e);  // ????
            }
        }

         xhr.send();
        queryTask.execute(query );
        queryTask.on("complete", function(evt1) {
            deferredTask1.resolve(evt1);
        });


        all([deferredTask1deferredTask2]).then(function(results) {  //??
    
            var t=results;
        });
    });
</script>
</body>

Outcomes