Skip to content

Instantly share code, notes, and snippets.

@ahmednasir91
Created February 25, 2013 18:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ahmednasir91/5032163 to your computer and use it in GitHub Desktop.
Save ahmednasir91/5032163 to your computer and use it in GitHub Desktop.
$("#searchterm").keyup(function(e){
var q = $("#searchterm").val();
$.getJSON("http://en.wikipedia.org/w/api.php?callback=?",
{
srsearch: q,
action: "query",
list: "search",
format: "json"
},
function(data) {
$("#results").empty();
$("#results").append("<p>Results for <b>" + q + "</b></p>");
$.each(data.query.search, function(i,item){
$("#results").append("<div><a href='http://en.wikipedia.org/wiki/" + encodeURIComponent(item.title) + "'>" + item.title + "</a><br>" + item.snippet + "<br><br></div>");
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment