< head >
<title>flickr JQuery Template</title>
<script type="text/javascript" src="js/code.jquery.com%20jquery-1.4.2.js"/>
<script type="text/javascript" src="js/jquery-ui-1.8.5.custom.min.js"/>
<script type="text/javascript" src="js/jquery.tmpl.js"/>
</ head >
< script id="flickrTemplate" type="text/html">
<div>
<h2>${title}</h2>
<img src="http://farm5.static.flickr.com/${server}/${id}_${secret}_t.jpg"
title="${title}"
alt="${title}" />
</div>
</ script >
< div id="interesting_photos"></div>
//
// build the html
$("#flickrTemplate")
.tmpl(rsp.photos.photo)
.appendTo("#interesting_photos");
<? xml version="1.0" encoding="UTF-8"?>
<! 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">
< body >
<div id="interesting_photos"></div>
<script type="text/javascript">
// Flickr REST url
var url = "http://api.flickr.com/services/rest/?";
// My Flickr API key
var api_key = "--your flickr api key here--";
// get interesting photos
function getInterestingPhotos() {
// build the URL
var call = url + "method=flickr.interestingness.getList&api_key="
+ api_key
+ "&per_page=5&page=1&format=json&jsoncallback=?";
// make the ajax call
$.getJSON(call, function (rsp) {
if (rsp.stat != "ok") {
// something went wrong!
$("#interesting_photos").append(
"<label style=\"color:red\">Whoops! It didn't work!" +
" This is embarrassing! Here's what Flickr had to " +
" say about this - " + rsp.message + "</label>");
}
else {
});
</script>
$(function () {
$(getInterestingPhotos);
})
</ body >
</ html >