Created
July 28, 2011 11:48
-
-
Save theClarkSell/1111427 to your computer and use it in GitHub Desktop.
Consuming an OData Service from jQuery
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" /> | |
<meta name="author" content="Clark Sell" /> | |
<title>Consuming an OData Service from jQuery</title> | |
<script type="text/javascript" src="http://ajax.microsoft.com/ajax/jquery/jquery-1.6.2.min.js"></script> | |
<script src="http://ajax.aspnetcdn.com/ajax/jquery.templates/beta1/jquery.tmpl.min.js"></script> <!-- http://api.jquery.com/category/plugins/templates/ --> | |
<script src="/scripts/dsshows.js"></script> | |
</head> | |
<body> | |
<p>On Developer Smackdown</p> | |
<script id="dsListTemplate" type="text/html"> | |
<ul> | |
<li><a href="${PublicUri}" target="blank">${Title}</a></li> | |
</ul> | |
</script> | |
<div id="ds_shows"></div> | |
</body> | |
</html> |
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
jQuery(document).ready(function () { | |
var query = "http://developersmackdown.com/services/odata/Shows" //root uri | |
+ "?$select=ShowId,Title,PublicUri" //reduce the payload to what we need | |
+ "&$orderby=ShowId%20desc" //order by and sort by the latest shows | |
+ "&$top=5" //take the top 5 | |
+ "&$format=json" //give me json | |
+ "&$callback=callback"; //this is my callback | |
jQuery.ajax({ | |
dataType: 'jsonp', | |
url: query, | |
jsonpCallback: 'callback', | |
success: callback | |
}); | |
function callback(result) { | |
var shows = result.d; | |
jQuery('#dsListTemplate').tmpl(shows).appendTo('#ds_shows'); | |
} | |
}); |
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
<body> | |
<p>On Developer Smackdown</p> | |
<script id="dsListTemplate" type="text/html"> | |
<ul> | |
<li><a href="${PublicUri}" target="blank">${Title}</a></li> | |
</ul> | |
</script> | |
<div id="ds_shows"></div> | |
</body> |
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
<script> | |
$(document).ready(function () { | |
var query = "http://developersmackdown.com/services/odata/Shows" //root uri | |
+ "?$select=ShowId,Title,PublicUri" //reduce the payload to what we need | |
+ "&$orderby=ShowId%20desc" //order by and sort by the latest shows | |
+ "&$top=5" //take the top 5 | |
+ "&$format=json" //give me json | |
+ "&$callback=callback"; //this is my callback | |
$.ajax({ | |
dataType: 'jsonp', | |
url: query, | |
jsonpCallback: 'callback', | |
success: callback | |
}); | |
function callback(result) { | |
var shows = result.d; | |
$('#dsListTemplate').tmpl(shows).appendTo('#ds_shows'); | |
} | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment