-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathx-CDOrequest.html
73 lines (66 loc) · 2.23 KB
/
x-CDOrequest.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
<!DOCTYPE html>
<html>
<meta charset="utf-8">
<link rel="shortcut icon" href="resources/favicon.ico" />
<meta name="author" content="Martin Roberge" />
<title>CDO request page</title>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<style>
header {
font-family: Arial, sans-serif;
color: green;
background-color: darkgray;
}
.ready {
background-color: yellow;
}
</style>
<script src="lib/jquery/jquery-2.0.2.js"></script>
<body>
<header>
<h1>CDO Data Request Page</h1>
</header>
<p>I finally have this working!</p>
<p>Learn more here: <a href="https://www.ncdc.noaa.gov/cdo-web/webservices/v2">https://www.ncdc.noaa.gov/cdo-web/webservices/v2</a></p>
<hr><br/>
<div id="target"> </div>
<script>
// A working request (must also add header)
//https://www.ncdc.noaa.gov/cdo-web/api/v2/data?limit=1000&datasetid=PRECIP_15&stationid=COOP:180700&startdate=2000-01-01&enddate=2001-01-01
var url = "https://www.ncdc.noaa.gov/cdo-web/api/v2/data";
var myToken = "pWmAdZysIShKsPkxbGeKAjeutJYqpOus";
var request1 = {
"limit" : "1000",
"datasetid" : "PRECIP_15",
"stationid" : "COOP:180700",
"startdate" : "2000-01-01",
"enddate" : "2000-05-01"
};
// Another working request
// https://www.ncdc.noaa.gov/cdo-web/api/v2/data?limit=105&datasetid=GHCND&stationid=GHCND:USW00013872&startdate=2012-05-01&enddate=2012-06-02
var request2 = {
"datasetid" : "GHCND",
"stationid" : "GHCND:USW00013872",
"startdate" : "2012-05-01",
"enddate" : "2012-06-02",
"limit" : "105"//default is 25
};
function CDOrequest(myData) {
$("#target").append("<p>starting request using " + JSON.stringify(myData) + "</p>");
console.log("starting request...");
$.ajax({
url : url,
data : myData,
headers : {
"token" : myToken
}
}).done(function(data) {
console.log(data);
$("#target").append(JSON.stringify(data)).addClass("ready");
});
}
CDOrequest(request1);
CDOrequest(request2);
</script>
</body>
</html>