gpt4 book ai didi

javascript - Backbone fetch 在 IE9 及更低版本中不起作用

转载 作者:行者123 更新时间:2023-11-28 20:03:53 24 4
gpt4 key购买 nike

所以我下面的应用程序进行 ajax 调用并使用 Backbone 解析请求。除 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

关于javascript - Backbone fetch 在 IE9 及更低版本中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21176290/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com