简体   繁体   English

骨干获取无法在IE9及以下版本中使用

[英]Backbone fetch wont work in IE9 and below

So I have this application below making an ajax call and parsing the request using backbone. 因此,我在下面进行了Ajax调用并使用骨干解析请求的应用程序。 Everything works perfectly in all browsers except for ie9 and below. 除了ie9及以下版本,其他所有浏览器都可以正常运行。 I cant seem to figure out what the problem is and why it seems to always fail on the fetch() in IE9 and below. 我似乎无法弄清楚问题是什么,以及为什么它似乎总是在IE9及以下版本的fetch()上失败。

Any help would be greatly appreciated! 任何帮助将不胜感激!

    window.ScheduleApp = {
        Models: {},
        Collections: {},
        Views: {}
    };

    window.template = function(id) {
        return _.template($('#' + id).html());
    };

    //Define the Game Model.
    ScheduleApp.Game = Backbone.Model.extend({
        initialize: function() {
            this.gameId = this.get('Id');
            this.gameTime = this.get('Time');
        }
    });

    //Define the Games Collection that contains Game Models.
    ScheduleApp.Games = Backbone.Collection.extend({
        model: ScheduleApp.Game
    });

    //Define the Day Model.
    ScheduleApp.Day = Backbone.Model.extend({
        initialize: function() {
            this.games = new ScheduleApp.Games(this.get('Games'));
            this.games.parent = this;
            this.gameDayDate = this.get('Date');
        }
    });

    //Define the Days Collection that contains the Day Models.
    ScheduleApp.Days = Backbone.Collection.extend({
        model: ScheduleApp.Day,
        url: function() {
            return '//domain/jsonfile.json'
        },
        parse: function(data) {
            var parsedSchedule = JSON.parse('[' + data + ']');
            console.log(parsedSchedule);
            return parsedSchedule;

        }
    });

    ScheduleApp.DayCollectionView = Backbone.View.extend({
        el: '.container', //Container where the views get rendered to.

        initialize: function() {
            this.listenTo(this.collection, 'reset', this.render);
        },
        render: function(event) {

            //Cycle through collection of each day.
            this.collection.each(function(day) {
                console.log(day);

                var dayView = new ScheduleApp.DayView({
                    model: day
                });

                this.$el.append(dayView.render().el);

            }, this);
            return this;
        }
    });

    ScheduleApp.DayView = Backbone.View.extend({
        tagName: 'div', 
        className: 'game-date', 
        template: _.template($("#gameDaySchedule").html(), this.model), 
        initialize: function() {
            this.listenTo(this.model, "reset", this.render);
        },
        render: function() {
            this.$el.html(this.template(this.model.toJSON()));
            return this;
        }
    });

    var daysList = new ScheduleApp.Days();

    daysList.fetch({
        reset: true,
        update: true,
        cache: false,
        success: function(collection, response) {
            console.log(collection);
        },
        error: function(model, resp) {
            console.log('error arguments: ', arguments);
            console.log("error retrieving model");
        }

    });

    //create new collection view.
    var daysCollectionView = new ScheduleApp.DayCollectionView({
        collection: daysList
    });

This solved my issue I was having. 这解决了我遇到的问题。 Turns out it was the cross domain request I was making getting my json. 原来这是我正在获取json的跨域请求。

https://github.com/victorquinn/Backbone.CrossDomain https://github.com/victorquinn/Backbone.CrossDomain

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM