Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #5 from dale3253/patch-1

Update examples/restful-app/index.html
  • Loading branch information...
commit 5a5a73967f63f45b8af04bd13a17eaf5a6c08309 2 parents d2edf7f + b71fa2b
Thomas Davis authored
Showing with 56 additions and 62 deletions.
  1. +56 −62 examples/restful-app/index.html
118 examples/restful-app/index.html
View
@@ -1,70 +1,64 @@
-<!DOCTYPE html>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
- <title>Hide your kids, hide your wife and hide your husbands</title>
+ <title>Router</title>
+ <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
+ <script type="text/javascript" src="http://ajax.cdnjs.com/ajax/libs/underscore.js/1.3.3/underscore-min.js"></script>
+ <script type="text/javascript" src="http://ajax.cdnjs.com/ajax/libs/backbone.js/0.9.2/backbone-min.js"></script>
+ <script type="text/javascript">
+ (function ($) {
+ var restfulApp = Backbone.Router.extend({
+ restfulUrl:"http://api.openkeyval.org/", //This is a free service to store key pair values
+ //Routes tell the app what to do
+ routes:{
+ "animals/:animal":"animalAction", //This matches app/animals/* and assigns * to a variable called "animal"
+ "*page":"defaultAction" //This simply matches any urls that weren't caught above and assigns it to "page"
+ },
+
+ defaultAction:function (page) {
+ if (page) {
+ //Once the default action is called we want to construct a link to our restful service
+ var restfulPageUrl = this.restfulUrl + page + 'page'; //http://api.openkeyval.org/gangsterpage
+ //Now we have a url lets get the data
+ this.loadRestfulData(restfulPageUrl);
+ }
+ },
+ animalAction:function (animal) {
+ //Once the default action is called we want to construct a link to our restful service
+ var restfulPageUrl = this.restfulUrl + animal + 'page'; //http://api.openkeyval.org/dogpage
+ //Now we have a url lets get the data
+ this.loadRestfulData(restfulPageUrl);
+ },
+ loadRestfulData:function (pageUrl) {
+ //Set the content pane to a loading screen
+ $('#content-pane').text('loading data...');
+ //Load the data in using jQuerys ajax call
+ $.ajax({
+ url:pageUrl,
+ dataType:'jsonp',
+ success:function (data) {
+ //Once we receive the data, set it to the content pane.
+ $('#content-pane').text(data);
+ }
+ });
+ }
+ });
+
+ new restfulApp;
+ //Initiate a new history and controller class
+ Backbone.emulateHTTP = true;
+ Backbone.emulateJSON = true;
+ Backbone.history.start();
+ })(jQuery);
+ </script>
</head>
<body>
-
<ul id="menu">
-<li><a href="#animals/dog">Dogs</a></li>
-<li><a href="#animals/cat">cats</a></li>
-<li><a href="#shop">Shops</a></li>
-<li><a href="#gangster">Gangsters</a></li>
+ <li><a href="#animals/dog">Dogs</a></li>
+ <li><a href="#animals/cat">cats</a></li>
+ <li><a href="#shop">Shops</a></li>
+ <li><a href="#gangster">Gangsters</a></li>
</ul>
<div id="content-pane">No content loaded</div>
-
-<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
-<script src="http://ajax.cdnjs.com/ajax/libs/underscore.js/1.1.4/underscore-min.js"></script>
-<script src="http://ajax.cdnjs.com/ajax/libs/backbone.js/0.3.3/backbone-min.js"></script>
-<script>
-(function ($) {
-
- var restfulApp = Backbone.Controller.extend({
- restfulUrl: "http://api.openkeyval.org/", //This is a free service to store key pair values
-
- //Routes tell the app what to do
- routes: {
- "animals/:animal": "animalAction", //This matches app/animals/* and assigns * to a variable called "animal"
- "*page": "defaultAction", //This simply matches any urls that weren't caught above and assigns it to "page"
- },
-
- defaultAction: function( page ){
- if( page ) {
- //Once the default action is called we want to construct a link to our restful service
- var restfulPageUrl = this.restfulUrl + page + "page" //http://api.openkeyval.org/gangsterpage
- //Now we have a url lets get the data
- this.loadRestfulData( restfulPageUrl );
- }
- },
- animalAction: function( animal ) {
- //Once the default action is called we want to construct a link to our restful service
- var restfulPageUrl = this.restfulUrl + animal + "page" //http://api.openkeyval.org/dogpage
- //Now we have a url lets get the data
- this.loadRestfulData( restfulPageUrl );
- },
- loadRestfulData: function( pageUrl ){
- //Set the content pane to a loading screen
- $("#content-pane").text( "loading data..." );
- //Load the data in using jQuerys ajax call
- $.ajax({
- url: pageUrl,
- dataType: "jsonp",
- success: function(data){
- //Once we receive the data, set it to the content pane.
- $("#content-pane").text( data );
- }
- });
- }
-
- });
-
- var app = new restfulApp;
- //Initiate a new history and controller class
- Backbone.emulateHTTP = true;
- Backbone.emulateJSON = true
- Backbone.history.start();
-
-})(jQuery);
-</script>
</body>
-</html>
+</html>
Please sign in to comment.
Something went wrong with that request. Please try again.