簡體   English   中英

骨干獲取無法在IE9及以下版本中使用

[英]Backbone fetch wont work in IE9 and below

因此,我在下面進行了Ajax調用並使用骨干解析請求的應用程序。 除了ie9及以下版本,其他所有瀏覽器都可以正常運行。 我似乎無法弄清楚問題是什么,以及為什么它似乎總是在IE9及以下版本的fetch()上失敗。

任何幫助將不勝感激!

    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
    });

這解決了我遇到的問題。 原來這是我正在獲取json的跨域請求。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM