-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
68 lines (64 loc) · 1.98 KB
/
index.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="author" content="Sapthesh V">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css">
<title>Narendra Modi News</title>
</head>
<body>
<nav>
<div class="nav-wrapper blue">
<a href="/news/v2/" class="brand-logo center">Any News</a>
</div>
</nav>
<div class="container">
<div id="newsList"></div>
<div id="loading" class="progress">
<div class="indeterminate"></div>
</div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js"></script>
<script>
$(document).ready(function() {
loadNews();
function loadNews() {
$("#loading").show();
$.ajax({
url: "fetch_news.php",
type: "GET",
success: function(response) {
$("#newsList").empty();
if (response.length > 0) {
$.each(response, function(index, article) {
var newsItem = `
<div class="card">
<div class="card-content">
<span class="card-title">${article.title}</span>
<p>${article.description}</p>
</div>
<div class="card-action">
<a href="article.php?id=${article.id}">Read More</a>
</div>
</div>
`;
$("#newsList").append(newsItem);
});
} else {
$("#newsList").html("<p>No news articles found.</p>");
}
},
error: function() {
$("#newsList").html("<p>Error occurred while fetching news.</p>");
},
complete: function() {
$("#loading").hide();
}
});
}
});
</script>
</body>
</html>