Advertisement
jrrewers

Untitled

Feb 5th, 2017
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. 'use strict';
  2.  
  3. $(document).ready(function () {
  4.     var $submit = $("#submit"),
  5.         $city = $("#city");
  6.  
  7.     $submit.on("click", function () {
  8.  
  9.         // wysyłamy żądanie pod url opisany w dokumentacji http://www.apixu.com/doc/
  10.         $.ajax({
  11.             url: `http://api.apixu.com/v1/current.json?key=298458f3e7fc426bacc84203170502&q=${$city.val()}`,
  12.             type: "get"
  13.         }).done(function (weather) {
  14.             // po odebraniu danych wywyoła się funkcja done()
  15.             console.log(weather);
  16.             var $newP = $("<p>"),
  17.                 text = `Weather in ${weather.location.name}, ${weather.location.country}: Temp: ${weather.current.temp_c}, Clouds: ${weather.current.cloud}, Pressure: ${weather.current.pressure_mb}`;
  18.             $newP.text(text);
  19.             $newP.appendTo($("body"));
  20.         }).fail(function (error) {
  21.             console.error(error);
  22.         })
  23.     })
  24. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement