Skip to content

Instantly share code, notes, and snippets.

@andygup
Created March 14, 2017 16:35
Show Gist options
  • Select an option

  • Save andygup/f92d132e662ff42f595bbdfecfbf6dc5 to your computer and use it in GitHub Desktop.

Select an option

Save andygup/f92d132e662ff42f595bbdfecfbf6dc5 to your computer and use it in GitHub Desktop.
Geoenrichment request
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>XHR</title>
</head>
<body>
<div id="result">Some result goes here</div>
<script>
var url = "https://geoenrich.arcgis.com/arcgis/rest/services/World/geoenrichmentserver/GeoEnrichment/enrich";
var req = new XMLHttpRequest();
req.open("POST", url, true);
req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
req.onload = function()
{
if( req.status === 200 && req.responseText !== "")
{
var obj = JSON.parse(this.response);
console.log(obj);
document.getElementById("result").innerText = "OBJECTID = " + obj.results[0].value.FeatureSet[0].features[0].attributes.OBJECTID;
}
};
req.onerror = function(e)
{
console.log("_makeEditRequest failed: " + e);
};
// NOTE: token only good for 24 hours ;-)
req.send(
"f=json" +
"&studyAreas=[{'geometry':{'x':-122.435,'y':37.785}}]" +
"&token=6k9vrM5j-RIFDOHGbf8sXgnqROd7o2pj_q_D3ZteIEliACScLMtP1JBLzj8auCbWpMY0FK3TTU3R0vP64dcoe9xAQOEGp7LZpgw1z6jmc6Chjp4d1aCpYdhJl3X9dNREAeG46gzIZnvZ54Uq_0nCnw.."
);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment