-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
48 lines (41 loc) · 1.41 KB
/
Copy pathscript.js
File metadata and controls
48 lines (41 loc) · 1.41 KB
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
$('form').on('submit', function(e) {
e.preventDefault();
var date = $('input').val();
apod.init(date);
});
var apod = {
init: function(date) {
this.load(date);
},
load: function(date) {
var API_KEY = 'KR1va14h1PqLZwhfsKqImgBGT3VqGMfPDpMQhdNB';
var showDate = date;
$.ajax('https://api.nasa.gov/planetary/apod?api_key='+ API_KEY +'&date=' + date, {
dataType: 'json',
success: function(result) {
console.log(result);
var $title = $('<h1><strong>' + result.date + ' </strong>' + result.title + '</h1>');
$('.apod').append($title);
var $explanation = $('<div>' + result.explanation + '</div>').addClass('gen-text');
$('.apod').append($explanation);
var $icon = $('<img>');
$icon.attr('src', '' + result.url);
$('.apod').append($icon);
},
error: function(error) {
$('.apod').text(error.responseText);
$('.logo').hide();
},
beforeSend: function() {
$('.apod').empty();
$('.loader').show();
$('.logo').hide();
},
complete: function() {
$('.loader').hide();
$('.apod').show();
$('.logo').show();
}
});
}
}