-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhowToReadJson.html
98 lines (84 loc) · 2.98 KB
/
howToReadJson.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<!DOCTYPE html>
<html>
<head>
<title>JSON Content</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="stylesheet" href="https://js.arcgis.com/3.20/esri/css/esri.css">
<style>
body{
font-family: "Arial Unicode MS, Arial, sans-serif";
}
#content {
width: 800px; height: 350px; padding: 5px; overflow: auto;
border: solid 2px #AAAAAA; background-color: #FFFFFF;
-moz-border-radius: 5px; -webkit-border-radius: 5px; -o-border-radius: 5px; border-radius: 5px;
-moz-box-shadow: 0 0 0.5em black; -webkit-box-shadow: 0 0 0.5em black; -o-box-shadow: 0 0 0.5em black; box-shadow: 0 0 0.5em black;
}
.failure { color: red; }
#status { font-size: 12px; }
</style>
<script src="https://js.arcgis.com/3.20/"></script>
<script>
require([
"dojo/dom",
"dojo/on",
"dojo/dom-class",
"dojo/_base/json",
"esri/config",
"esri/request",
"dojo/domReady!"
],
function(
dom,
on,
domClass,
dojoJson,
esriConfig,
esriRequest
) {
// Pass URL value and use proxy to bypass CORS
dom.byId("url").value = "InternationalStudentCount.json";
esriConfig.defaults.io.proxyUrl = "/proxy/";
// Or live feed
// dom.byId("url").value = "http://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/1.0_day.geojson"; // live feed (but doesn't support https/cors)
// proxy required for http://earthquake.usgs.gov
dom.byId("content").value = "";
//handle the Go button's click event
on(dom.byId("submitRequest"), "click", getContent);
function getContent(){
var contentDiv = dom.byId("content");
contentDiv.value = "";
domClass.remove(contentDiv, "failure");
dom.byId("status").innerHTML = "Downloading...";
var requestHandle = esriRequest({
"url": dom.byId("url").value
});
requestHandle.then(requestSucceeded, requestFailed);
}
function requestSucceeded(response, io){
dom.byId("status").innerHTML = "";
dojoJson.toJsonIndentStr = " ";
dom.byId("content").value = dojoJson.toJson(response, true);
}
function requestFailed(error, io){
domClass.add(dom.byId("content"), "failure");
dom.byId("status").innerHTML = "";
dojoJson.toJsonIndentStr = " ";
dom.byId("content").value = dojoJson.toJson(error, true);
}
});
</script>
</head>
<body>
<p>Download content available in <b>JSON</b> format using esriRequest. </p>
<p>
<input type="text" disabled="true" id="url" size="100"/>
<input id="submitRequest" type="button" value="GO" />
<span id="status"></span>
</p>
<p>
<h2>Content</h2>
<textarea id="content"></textarea>
</p>
</body>
</html>