Skip to content

Instantly share code, notes, and snippets.

@pranid
Created August 17, 2017 04:27
Show Gist options
  • Save pranid/c18b094b3ff726b4fcd9bc20d3174e9a to your computer and use it in GitHub Desktop.
Save pranid/c18b094b3ff726b4fcd9bc20d3174e9a to your computer and use it in GitHub Desktop.
Get countries from restcountries.eu and Display it using Bootstrap & Jquery
<!DOCTYPE html>
<html>
<head>
<title>API TEST</title>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
</head>
<body>
<div class="container">
<div class="row">
<div class="col-md-8 col-md-offset-1">
<h2>Country Table</h2>
<hr>
</div>
</div>
<div class="row">
<div class="col-md-8 col-md-offset-2">
<table class="table table-striped" id="country-table">
<thead>
<tr>
<th>Flag</th>
<th>Country Name</th>
<th>Currency Code</th>
</tr>
</thead>
<tbody></tbody>
</table>
</div>
</div>
</div>
<script
src="https://code.jquery.com/jquery-2.2.4.min.js"
integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44="
crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<script type="text/javascript">
jQuery(document).ready(function($) {
$.get('//restcountries.eu/rest/v2/all', function(data) {
$.each(data, function(index, val) {
var html = '<tr>';
html += '<td><img src="'+ val.flag+'" alt="'+ val.name+'" width="50px"/></td>';
html += '<td>'+ val.name+'</td>';
html += '<td>';
$.each(val.currencies, function(index, val) {
if(val.code != null) {
html += val.code + ' ';
}
});
html += '</td>';
html += '</tr>';
$('#country-table tbody').append(html);
});
});
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment