Professional Documents
Culture Documents
PRACTICAL7
PRACTICAL7
21/5005
PRACTICAL-7
Store JSON data of few pets that you
created in previous practical in a JSON
file (copy from console output of previous
program to a .json file). Using AJAX, load
data from the file and display it in a
presentable way using HTML and CSS.
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Pets Information</title>
</head>
<body>
<div id="pets-container"></div>
<script src="https://code.jquery.com/jquery-3.6.4.min.js"></script>
<script src="script.js"></script>
</body>
</html>
CSS
#pets-container {
max-width: 600px;
.pet {
padding: 10px;
margin-bottom: 10px;
border-radius: 5px;
.pet h2 {
margin-top: 0;
.pet p {
margin-bottom: 5px;
JAVASCRIPT
$(document).ready(function() {
$.ajax({
url: 'pets.json',
type: 'GET',
dataType: 'json',
success: function(data) {
displayPets(data);
},
error: function() {
});
function displayPets(pets) {
pets.forEach(function(pet) {
petsContainer.append(petDiv);
});
});
A.