-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
111 lines (73 loc) · 2.71 KB
/
script.js
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
99
100
101
102
103
104
105
106
107
108
109
110
111
function getWeather() {
var city = $('#city').val()
$.ajax({
url: { CURRENT_WEATHER_API },
type: "get",
success: function(data) {
$(city_name).html(data.name);
$(temp).html(+data.main.temp + "°C");
$(main).html(data.weather[0].main)
$(desc).html(data.weather[0].description)
}
})
// me
// $.ajax({
// url: "https://api.openweathermap.org/data/2.5/forecast?q=" + city + "&appid=5103d69bb8ef78059397045586ea6ea7&units=metric",
// type: "get",
// success: function(data) {
// for (let i = 0; i <= data.list.length; i++) {
// html(console.log(data.list[i].dt_txt));
// }
// for (let i = 0; i <= data.list.length; i++) {
// $(mpp).html(console.log(data.list[i].main.temp));
// }
// }
// })
console.log(city)
// document.querySelector("#city").addEventListener("keypress", function(event)){
// if(event.keycode == "13") {
// getWheather();
// }
// getbg(city)
DataTable(city)
console.log(city)
}
// function getbg(city) {
// document.body.style.backgroundImage = "url('https://source.unsplash.com/1920x1080/?" + city + "')"
// }
$('#table').hide()
function DataTable(city) {
var spinner = new jQuerySpinner({
parentId: 'div_loading'
});
spinner.show();
$.ajax({
url: { WEATHER_FORCAST_API },
type: "get",
success: function(data) {
for (i = 0; i < data.list.length; i++) {
var tr = "<tr class='text-center'>";
var td0 = "<td>" + data.list[i]["dt_txt"] + "</td>";
var td1 = "<td>" + data.list[i]["weather"][0]["main"] + "</td>";
var td2 = "<td>" + data.list[i]["main"]["temp"] + "</td>";
var td3 = "<td>" + data.list[i]["main"]["humidity"] + "</td>";
var td4 = "<td>" + data.list[i]["main"]["pressure"] + "</td> </tr>";
// var td5 = "<td>" + value[i]['strPresenatge'] + "</td></tr>";
var final = $("#weathertable").append(tr + td0 + td1 + td2 + td3 + td4);
// console.log(data.list[i]["dt_txt"]);
// console.log(data.list[i]["main"]["temp"]);
// //console.log(data.list[i].dt_txt);
console.log(final)
}
$('#table').show()
$('#weathertable').DataTable().destroy();
$('#weathertable').DataTable({
dom: 'Bfrtp',
buttons: [
'pdf'
]
});
spinner.hide();
}
})
}