Skip to content

Instantly share code, notes, and snippets.

@rightson
Created July 15, 2012 04:55

Revisions

  1. rightson revised this gist Jul 16, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion backbone5-ajax.html
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,7 @@
    <html lang="en-US">
    <head>
    <meta charset="UTF-8">
    <title>Learning About Backbone.js Routers</title>
    <title>Learning About Backbone.js AJAX</title>
    </head>
    <body>

  2. rightson revised this gist Jul 15, 2012. 1 changed file with 5 additions and 5 deletions.
    10 changes: 5 additions & 5 deletions backbone5-ajax.html
    Original file line number Diff line number Diff line change
    @@ -17,13 +17,13 @@
    var Person = Backbone.Model.extend({
    initialize: function() {
    this.on('all', function(e) {
    alert(this.get('name') + " event: " + e); });
    console.log(this.get('name') + " event: " + e); });
    },
    defaults: {
    name: 'undefined',
    age: 'undefined'
    },
    urlRoot: "/examples/backbone.php",
    urlRoot: "/examples/backbonejs-ajax/backbone.php",
    url: function() {
    var base = this.urlRoot || (this.collection && this.collection.url) || "/";
    if (this.isNew()) return base;
    @@ -43,10 +43,10 @@

    var People = Backbone.Collection.extend({
    initialize: function() {
    this.on('all', function(e) { alert("People event: " + e); });
    this.on('all', function(e) { console.log("People event: " + e); });
    },
    model: Person,
    url: "/examples/backbone.php"
    url: "/examples/backbonejs-ajax/backbone.php"
    });

    var people = new People();
    @@ -55,4 +55,4 @@
    people.create({id:6, name:"Chuck Norris", age:72});
    </script>
    </body>
    </html>
    </html>
  3. rightson created this gist Jul 15, 2012.
    58 changes: 58 additions & 0 deletions backbone5-ajax.html
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,58 @@
    <!DOCTYPE HTML>
    <html lang="en-US">
    <head>
    <meta charset="UTF-8">
    <title>Learning About Backbone.js Routers</title>
    </head>
    <body>

    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
    <script type="text/javascript" src="http://documentcloud.github.com/underscore/underscore-min.js"></script>
    <script type="text/javascript" src="http://documentcloud.github.com/backbone/backbone-min.js"></script>
    <script type="text/javascript">

    Backbone.emulateHTTP = true;
    Backbone.emulateJSON = true;

    var Person = Backbone.Model.extend({
    initialize: function() {
    this.on('all', function(e) {
    alert(this.get('name') + " event: " + e); });
    },
    defaults: {
    name: 'undefined',
    age: 'undefined'
    },
    urlRoot: "/examples/backbone.php",
    url: function() {
    var base = this.urlRoot || (this.collection && this.collection.url) || "/";
    if (this.isNew()) return base;
    return base + "?id=" + encodeURIComponent(this.id);
    }
    });

    var person = new Person({id:1});
    person.fetch();

    person = new Person({name:"Joe Zim", age:23});
    person.save();

    person = new Person({id:1, name:"Joe Zim", age:23});
    person.save();
    person.destroy();

    var People = Backbone.Collection.extend({
    initialize: function() {
    this.on('all', function(e) { alert("People event: " + e); });
    },
    model: Person,
    url: "/examples/backbone.php"
    });

    var people = new People();
    people.fetch();
    people.create({name:"Joe Zim", age:23});
    people.create({id:6, name:"Chuck Norris", age:72});
    </script>
    </body>
    </html>