https://github.com/mroberge/HydroCloud
Raw File
Tip revision: 4d2f3243b15298d0bffb66db430a02982a638ab4 authored by Martin Roberge on 09 April 2018, 02:46:03 UTC
Merge pull request #123 from mroberge/Feedback
Tip revision: 4d2f324
x-CDOrequest.html
<!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>
back to top