Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">

<title>Labtest Jquery Ronnie</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- <link rel="stylesheet" type="text/css" media="screen" href="main.css" /> -->

<script src="index.js"></script>

</head>
<body>

<h1>Nasa Image Previewer</h1>
<div class="searchBar">

<h2>Search Term: <input id="search" type="text"></h2>
<button id="button">Search Button</button>
</div>

<div class="container">
<!-- <ul> id= "pictures">

</ul>
-->
</div>

<div>
<button id="button">12 New Images</button>
</div>

</body>
</html>
49 changes: 49 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
//Populate 12 Pictures to Container class
function addPicture(picture){
for (i = 0; i < 12; i++){

$('#container').prepend($('<img>', {id='pic', src='picture.collection.items[i].links[0].href',
height='400', width= '400', style='border:2px solid black'}))

}
}
$(document).ready(function (){

var $pictures = $('#pictures');

//get request
$.ajax({
type: 'GET',
url:'https://images-api.nasa.gov/',
success: function(pictures){
console.log('success', pictures);
$.each(pictures, function(x, picture){
//call add picture function
addPicture(picture);
});
},
// Error message
error: function(){
alert('loading error');
}
});

$('button').on('click', function(){

$.ajax({
type: 'GET',
url:'https://images-api.nasa.gov/',
success: function(newPictures){
console.log('success', newPictures);
addPicture(picture);

},
//Error Message
error: function(){
alert('loading error');
}
});

});

})