Created
March 9, 2016 19:29
-
-
Save iheartkode/577028e44b2d90f49e25 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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