Created
August 7, 2012 19:29
-
-
Save jonmarkgo/3288649 to your computer and use it in GitHub Desktop.
This file contains hidden or 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> | |
<head> | |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript"></script> | |
<script type="text/javascript"> | |
$(function() { | |
$("#searchbutton").click(function () { | |
// Build OData query | |
var movieName = $("#search").val(); | |
var query = "http://odata.netflix.com/Catalog" // netflix base url | |
+ "/Titles" // top-level resource | |
+ "?$filter=substringof('" + escape(movieName) + "',Name)" // filter by movie name | |
+ "&$callback=callback" // jsonp request | |
+ "&$format=json"; // json request | |
console.log(query); | |
// Make JSONP call to Netflix | |
$.ajax({ | |
dataType: "jsonp", | |
url: query, | |
jsonpCallback: "callback", | |
success: callback | |
}); | |
}); | |
}); | |
function callback(result) { | |
$('#results').html(''); | |
var movies = result["d"]["results"]; | |
for (var i = 0; i < movies.length; i++) { | |
$('#results').append(movies[i].Name + '<br />'); | |
} | |
} | |
</script> | |
</head> | |
<body> | |
<input type="text" id="search" name="searchbox"> | |
<button id="searchbutton">Search</button> | |
<div id="results"></div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment