【问题标题】:backbone fetch: {“readyState”:0,“responseText”:“”,“status”:0,“statusText”:“error”} only on mobile主干获取:{“readyState”:0,“responseText”:“”,“status”:0,“statusText”:“error”} 仅在移动设备上
【发布时间】: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


    【解决方案1】:

    两天后,我发现问题出在我的服务器端,我的休息方法不允许跨源。设置好之后,..一切正常。

    【讨论】:

      猜你喜欢
      • 2014-12-17
      • 2011-10-24
      • 2013-10-24
      • 2018-12-24
      • 2020-11-26
      • 1970-01-01
      • 1970-01-01
      • 2016-05-20
      • 1970-01-01
      相关资源
      最近更新 更多