-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSearch.js
More file actions
49 lines (41 loc) · 1.48 KB
/
Search.js
File metadata and controls
49 lines (41 loc) · 1.48 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
49
$(document).ready(function(){
//#SearchButton is clicked
//Get the value from SearchInput
//Call the callNasaAPI() function with the input value
$("#SearchButton").click(function(){
var searchInput = $("#SearchInput").val();
callNasaAPI(searchInput);
});
function callNasaAPI(search){
var nasaURL = nasaSearchInput(search);
$.ajaxPrefilter({
url: nasaURL,
method: "GET",
success: function(response){
//console.log(response.collection.href)
var url = response.collection.href
console.log(url)
appendToRoot(url);
}
})
}
function appendToRoot(srcURL){
$("#root").html("");
$("#root").append("<img src="+srcURL+">");
}
//function nasaSearchInput(search){
// var nasaURL = 'https://cors-anywhere.herokuapp.com/' + "https://images-api.nasa.gov/search?q="+search;
// return nasaURL;
//}
jQuery.ajaxPrefilter(function nasaSearchInput(search){
if(search.crossDomain && jQuery.support.cors){
var nasaURL = "https://cors-anywhere.herokuapp.com/" + "https://images-api.nasa.gov/search?q="+search;
return nasaURL;
}
});
/*jQuery.ajaxPrefilter(function(options) {
if (options.crossDomain && jQuery.support.cors) {
options.url = 'https://cors-anywhere.herokuapp.com/' + options.url;
}
});*/
});