Advertisement
mbruns

JSON requests using API in Javascript

Jun 11th, 2022
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*Writing JSON requests for data with an API, in Javascript*/
  2.  
  3. <html>
  4.    <meta charset="UTF-8">
  5.    <head>
  6.       <title>Sample page</title>
  7.       <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
  8.       <script>
  9.       var settings = {
  10.         "url": "https://api.openweathermap.org/data/2.5/weather?zip=95050&units=imperial&appid=APIKEY",
  11.         "method": "GET",
  12.         "timeout": 0,
  13.       };
  14.  
  15.       $.ajax(settings).done(function (response) {
  16.         console.log(response);
  17.         var content = response.wind.speed;
  18.         $("#windSpeed").append(content);
  19.       });
  20.  
  21.       </script>
  22.    </head>
  23.    <body>
  24.       <h1>Sample Page</h1>
  25.       wind speed: <span id="windSpeed"></span>
  26.    </body>
  27. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement