【发布时间】:2017-01-14 01:39:59
【问题描述】:
我试图弄清楚这一点(已经有很多关于这个问题的帖子),但不幸的是我无法弄清楚。
我尝试使用一项简单的服务来获取和显示一些数据。在桌面上一切正常,但在移动设备上,我总是在每次获取以下错误时遇到: alert('error:' + JSON.stringify(XMLHttpRequest)):
{“readyState”:0,“responseText”:“”,“status”:0,“statusText”:“error”}
这是我的代码:
$(window).load(function(){
var Tweet = Backbone.Model.extend({
defaults: function() {
return {
DateTime: 0,
Tweet: ""
};
}
});
var TweetsCollection = Backbone.Collection.extend({
model: Tweet,
url: "http://11.112.101.221:8880/bananas" //url was changed
});
this.tweetsCollection = new TweetsCollection();
this.tweetsCollection.fetch({
reset: true,
success: function(request, data){
//alert("success:" + data);
console.log("onSuccess")
},
error: function(request, error){
alert("error:" + JSON.stringify(error));
}
});
var TweetsView = Backbone.View.extend({
tagName: "li",
template: _.template($('#item-template').html()),
initialize: function() {
this.listenTo(this.model, 'change', this.render);
this.listenTo(this.model, 'destroy', this.remove);
},
// Re-render the titles of the todo item.
render: function(event) {
event && event.preventDefault();
this.$el.html(this.template(this.model.toJSON()));
return this;
},
// Remove the item, destroy the model.
clear: function() {
this.model.destroy();
}
});
var AppView = Backbone.View.extend({
el: $("#warnupapp"),
initialize: function() {
this.listenTo(tweetsCollection, 'add', this.addOne);
this.listenTo(tweetsCollection, 'all', this.render);
this.main = $('#main');
console.log("fetching..")
tweetsCollection.fetch();
},
render: function() {
this.main.show();
},
addOne: function(tweet) {
var view = new TweetsView({model: tweet});
this.$("#tweets-list").append(view.render().el);
}
});
console.log("starting..")
var App = new AppView;
});
【问题讨论】:
标签: javascript ajax backbone.js