Skip to content

Instantly share code, notes, and snippets.

@iheartkode
Created March 9, 2016 19:29
Show Gist options
  • Save iheartkode/577028e44b2d90f49e25 to your computer and use it in GitHub Desktop.
Save iheartkode/577028e44b2d90f49e25 to your computer and use it in GitHub Desktop.
var searchWords;
var resultQuantity;
var searchURL;
$(document).ready(function(){
$('#submitBtn').on('click', function(){
searchWords = encodeURIComponent(document.getElementById("searchBox").value);
//$("#returnResults").append('<li><a href="/user/messages">'+ searchWords + '</a></li>')};
searchURL = 'http://en.wikipedia.org/w/api.php?action=query&format=json&list=search&utf8=1&srsearch='+searchWords+'&srprop=snippet&callback=?';
getWiki();
});
});
function getWiki(){
$.getJSON(searchURL, function(data) {
resultQuantity = data.query.search.length;
if (resultQuantity > 0){
$.each(data.query.search, function(i, item) {
$('#returnResults').append('<li>'+item.title+'<br>'+item.snippet+'</li>');
$("li").mouseover(function(){
$("li").css("background", "yellow");
});
});
};
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment