Skip to content

Instantly share code, notes, and snippets.

@SamFleming
Created August 27, 2012 17:15
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save SamFleming/3490499 to your computer and use it in GitHub Desktop.
Save SamFleming/3490499 to your computer and use it in GitHub Desktop.
Ajax google image search - random thumbnail
$.ajax({
dataType: "jsonp",
url: 'http://ajax.googleapis.com/ajax/services/search/images',
data: {
v: "1.0",
rsz: 8,
q: "airplane"
},
success: function ( json ) {
var rand = Math.floor(Math.random() * json.responseData.results.length),
results = json.responseData.results;
$('img').attr('src', results[rand].tbUrl);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment