Inst
Inst

Reputation: 1

Backbone Collection fetch not working

Hello i have 1 collection and model:

var Album = Backbone.Model.extend({
                url: "api/album",

                defaults: {
                    name: ""
                }

            });

var AlbumCollection = Backbone.Collection.extend({
                url: "api/albums",
                model: Album
            });

If i try to fetch data from that url like this:

  var newCollection = AlbumCollection();
  newCollection.fetch({
                success: function(data) {
                    console.log(11)
                    console.log(data)
                }
            })

its does not fetch data from that url - models in collection are empty. And in network tab in browser - i see there is not www.myurl.com/api/albums - call...

but if if i use jquery get it works:

 $.get('api/albums', function(data) {
                console.log(data);
            })

return valid json.

I cant figure it out, i spent countless hours debuggin this, and searching for a problem, please help.

Upvotes: 0

Views: 725

Answers (1)

StateLess
StateLess

Reputation: 5402

you missed new keyword

   var newCollection = new AlbumCollection();
      newCollection.fetch({
                    success: function(data) {
                        console.log(11)
                        console.log(data)
                    }
                })

Upvotes: 1

Related Questions