I want to start using Backbone.js to better structure my JavaScript files. However, I do not want to repeat my application in order to release JSON through the API. Correct mine if I'm wrong, but so far I have the impression that I can still use Backbone.js, even without the JSON API. Now I am faced with a problem when my server returns HTML, but the Backbone model is not like and returns an error.
Basically, I want to load an HTML snippet depending on the category:
var Filter = Backbone.Model.extend({ url: '/filters/', }); var FilterView = Backbone.View.extend({ initialize: function() { this.model.on('change', this.updateFilter, this); this.changeFilter(); }, changeFilter: function() { this.model.fetch({data: $.param({category: this.options.category})}); }, updateFilter: function(filters) { console.log(filters); this.$el.html(filters); }, }); var filter = new Filter(); var filterView = new FilterView({ el: $( '#filterContainer' ), category: $( '#categorySlug' ).data( 'slug' ), model: filter, });
Now I thought that I could use this simple model to extract my HTML fragment through Ajax. The request works correctly, but Backbone returns an error and updateFilter will never be called.
Am I really not getting something? What do I need to change so that it works with HTML instead of a JSON response? Or should I not use the model at all?
webjunkie
source share