AnsweredAssumed Answered

QueryTask results not loading after refresh

Question asked by Jenn_88 on Nov 25, 2014
Latest reply on Nov 25, 2014 by Jenn_88

Hello!

 

I have a QueryTask script and it only works the first time in a given browser or computer (it worked once in Firefox, Chrome and IE on work computer, and once in Firefox on my home computer). Now, whenever I refresh or access the page again the results don't show. I don't have this problem if I return the results as text; I can refresh as many times as I want and it works fine. Yep, I've restarted and cleared caches! It's my first time trying to build a web map with querying functionality so I might be missing something really obvious... Please let me know if I need to explain something better, too! Thanks a bunch!

 

<!DOCTYPE HTML>
<html>
<head>
 <meta http-equiv="Content-Type" content="text/html;charset=utf-8" >
 <title>CRM Project Creator</title>
 <!--<link rel="stylesheet" type="text/css" href="style.css">--> 
 <link rel="stylesheet" href="http://js.arcgis.com/3.9/js/esri/css/esri.css"> 
 <script src="http://js.arcgis.com/3.9/"></script>

<script>
 var map;
 var symbol;
 require([
  "esri/map",
  "esri/layers/ArcGISDynamicMapServiceLayer",
  "esri/tasks/query", "esri/tasks/QueryTask",
  "esri/symbols/SimpleFillSymbol", "esri/symbols/SimpleLineSymbol", "esri/Color",
  "dojo/domReady!"

   ], function (
  Map, ArcGISDynamicMapServiceLayer,
  Query, QueryTask, SimpleFillSymbol, SimpleLineSymbol,
  Color) {

  map = new Map("map", { 
   basemap: "streets",
   center: [-122.86, 49.1],
   zoom: 10
  });

  // query code
  var query = new Query();
  var queryTask = new QueryTask("http://[redacted]/MapServer/50");
  query.where = "Project_Number LIKE '%00%'";
  query.returnGeometry = true;
  query.outFields = ["*"];
  //query.outSpatialReference = new esri.SpatialReference({wkid : 4326});
  queryTask.execute(query, showResults);

  symbol = new SimpleFillSymbol();
  symbol.setStyle(SimpleFillSymbol.STYLE_SOLID);
  symbol.setColor(new Color([255,0,255,1]));

  function showResults(results) {
   map.graphics.clear();
   var resultFeatures = results.features;
   for (i=0, il=resultFeatures.length; i<il; i++) {
    var graphic = resultFeatures[i];
    graphic.setSymbol(symbol);
    map.graphics.add(graphic);
   }
   // set the extents of the query results 
   var extent = esri.graphicsExtent(results.features);
   map.setExtent(extent.expand(1.5),true); 

  }
 });
</script>

</head>

<body>

 <div id="map" style="width:1280px;height:860px"></div>

</body>
</html>

Outcomes