-
-
Save psycalc/61364276b56171709cd2d4c122319a6f to your computer and use it in GitHub Desktop.
A search suggestion using jQueryUI autocomplete + Wikipedia API.
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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8" /> | |
<title>jQuery demo - wikipedia suggestion</title> | |
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css"> | |
</head> | |
<body> | |
<div class="input-widget"> | |
<input id="wiki-input" /> | |
</div> | |
<script src="http://code.jquery.com/jquery.js"></script> | |
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.min.js"></script> | |
<script> | |
// On document ready | |
$(function() { | |
$("#wiki-input").autocomplete({ | |
minLength: 1, | |
autofocus: true, | |
delay: 100, | |
source: function( request, response ) { | |
$.ajax ({ | |
url: 'http://en.wikipedia.com/w/api.php?action=opensearch&format=json&search=' + request.term, | |
dataType: 'jsonp', | |
contentType: 'application/json; charset=utf-8', | |
type: 'GET', | |
async: true, | |
success: function(wikidata) { | |
console.log('jquery ajax returned for search ' + request.term + ' in wikipedia'); | |
response(wikidata[1]); | |
}, | |
error: function(XMLHttpRequest, textStatus, errorThrown) { | |
response(""); | |
} | |
}) | |
} | |
}); | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment