-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
56 lines (50 loc) · 1.84 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
function getNews(query){
const url =
"https://newsapi.org/v2/top-headlines?country=us&category=" +
query +
"&apiKey=9327be809f0e42dfa50ada6b4468aa8a";
$.ajax({
url: url,
method: "GET",
dataType: "json",
beforeSend: function(){
$("#loader").show();
},
complete: function(){
$("#loader").hide();
},
success: function(news){
let output = "";
let latestNews = news.articles;
for(var i in latestNews){
output +=`
<div class="col l3 m6 s12">
<div class="card medium hoverable">
<div class="card-image">
<img src="${latestNews[i].urlToImage}" class="responsive-img alt="NA">
</div>
<div class="card-content">
<span class="card-title activator"><i class="material-icons right">more_vert</i></span>
<h6>${latestNews[i].title}</h6>
</div>
<div class="card-reveal">
<span class="card-title"><i class="material-icons right">close</i></span>
<p>${latestNews[i].description}</p>
</div>
<div class="card-action">
<a href="${latestNews[i].url}" class="btn" target="_blank">Read more</a>
</div>
</div>
</div>
`;
}
if(output !== ""){
console.log("Hemant");
$("#newsResults").html(output);
}
},
error:function(){
$("newsResults").html("Some Error Occured");
}
})
}