Skip to content

Instantly share code, notes, and snippets.

Created March 11, 2012 22:24
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save anonymous/2018447 to your computer and use it in GitHub Desktop.
Jquery autocomplete
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Demo</title>
<link type="text/css" href="css/ui-lightness/jquery-ui-1.8.18.custom.css" rel="stylesheet" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript" src="js/jquery-ui-1.8.18.custom.min.js"></script>
<script>
var apikey = "5xq9w7z2mp7a6cnchkfy52yd";
var baseUrl = "http://api.rottentomatoes.com/api/public/v1.0";
var moviesSearchUrl = baseUrl + '/movies.json?apikey=' + apikey;
var query = "Rocky";
$(document).ready(function() {
$("#sample").autocomplete({
source: function( request, response ) {
$.ajax({
url: moviesSearchUrl + '&q=' + encodeURI(query),
dataType: "jsonp",
success: function(data) {
var movies = data.movies;
response(function(movies) {
return {
label: movies.title,
value: movies.title
}
}));
}
});
}
});
});
</script>
</head>
<body>
<div>
<input id="sample" />
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment