api call in php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<!-- <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script> -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<!-- CSS only -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta1/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-giJF6kkoqNQ00vy+HMDP7azOuL0xtbfIcaT9wjKHr8RbDVddVHyTfAAsrekwKmP1" crossorigin="anonymous">
</head>
<body>
<table>
<thead>
<th>Country Name</th>
<th>Capital</th>
<th>Population</th>
<th>Area</th>
<th>Country Code</th>
<th>Timezones</th>
</thead>
<tbody id="result">
</tbody>
</table>
</body>
</html>
<script>
$(document).ready(function() {
$.ajax({
url: 'https://restcountries.eu/rest/v2/all',
type: 'GET',
dataType: 'json',
success: function(response) {
console.log(response);
var rs = "";
for (i in response) {
rs += "<tr>";
rs += "<td>" + response[i].name + "</td>"
rs += "<td>" + response[i].capital + "</td>"
rs += "<td>" + response[i].population + "</td>"
rs += "<td>" + response[i].area + "</td>"
rs += "<td>" + response[i].alpha2Code + "</td>"
rs += "<td>" + response[i].timezones + "</td>"
rs += "</tr>";
// console.log(rs);
}
document.getElementById("result").innerHTML = rs;
}
});
});
</script>
Comments
Post a Comment