Forum Moderators: open
<!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 ">
<html>
<head>
<title>API JSON Test</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.0/jquery.min.js"></script>
</head>
<body>
<script type="text/javascript">
$(document).ready(function(){
var timeService = "http://api.MYDOMAIN.com/api.php?key=abc&num=1&format=json&callback=?";
$.getJSON(timeService, function(data) {
$('showdata').html("<p>ulore="+data.name+" url="+data.url+" created="+data.created+"</p>");
});
});
</script>
<div id="showdata"></div>
</body>
</html>
The way JSONP works is simple, but requires a little bit of server-side cooperation. Basically, the idea is that you let the client decide on a small chunk of arbitrary text to prepend to the JSON document, and you wrap it in parentheses to create a valid JavaScript document (and possibly a valid function call).[bob.pythonmac.org...]