HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<title>doers.lk</title>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<style type="text/css" media="screen">
</style>
</head>
<body>
<p id="hello"></p>
</body>
</html>
JQUERY
$.getJSON('http://api.wipmania.com/jsonp?callback=?', function (data) {
alert('Latitude: ' + data.latitude +
'\n Longitude: ' + data.longitude +
'\n Country: ' + data.address.country);
});
DEMO HERE
I want to load this json data to the id="hello".What is the better way to do it ?
jQuery provide the .html() method that let you get/set the content of an element. In your callback you could select the element on its id and use the .html() method to add your content.
$.getJSON('http://api.wipmania.com/jsonp?callback=?', function (data) {
$("#hello").html('Latitude: ' + data.latitude +
'<br /> Longitude: ' + data.longitude +
'<br /> Country: ' + data.address.country);
});
Working example
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