可以在promise.all中一起使用xmlhttprequest和queryTask吗?

时间:2018-10-23 09:23:23

标签: promise xmlhttprequest arcgis

我有两个异步请求:

普通休息请求  使用queryTask请求arcigs地图服务 在上述两个响应返回之后,“ dojo / promise / all”能否支持promise.all处理响应?

以上两项休息服务均可供互联网用户使用。

我的代码如下所示。

<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([deferredTask1,  deferredTask2]).then(function(results) {  //??
     
            var t=results;
        });
    });
</script>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
</head>
<body>
<script src="https://js.arcgis.com/3.26/"></script>

</body>
</html>

0 个答案:

没有答案