I am beginner in programming, I want someone to give me an example to show me how to write JSON
data with HTML
text
<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-1.8.3.min.js"></script>
</head>
<body>
<h1>antar<h2>
<script>
$.getJSON('http://api.wipmania.com/jsonp?callback=?', function (data) {
document.open();
document.write('Latitude: ' + data.latitude + '\nLongitude: ' + data.longitude + '\nCountry: ' + data.address.country);
document.close();
});
</script>
</body>
</html>
You can add in your html something like:
<h2 id='lat'></h2>
<h2 id='long'></h2>
<h2 id='country'></h2>
and then refactor your script as:
$(document).ready(function(){
$.getJSON('http://api.wipmania.com/jsonp?callback=?', function (data) {
$("#lat").text(data.latitude);
$("#long").text(data.longitude);
$("#country").text(data.country);
});
});
Here a working example you can play with.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With