9

以下骨干collection.fetch 代码因某种原因触发,出错,然后跳转到错误处理程序(如预期的那样),但我真的不知道错误处理程序参数是什么。触发错误时,模型、xhr 和选项参数未定义。我究竟做错了什么?

  var onErrorHandler = function(model, xhr, options) {
      alert(options);
  };

  that.collection = new MembersCollection([]); 
  that.collection.fetch({ success : onDataHandler, error: onErrorHandler, dataType: "jsonp" });

@muistooshort:我完全忘记了 js 参数,谢谢你的提示。

这是我发现的...

Arguments[0] = looks like its just the letter "d"
Arguments[1] = is an object. Has readyState, responseText, status, statusText
Arguments[2] = is an object. Exactly the same as [1]

状态 = 200,文本为“OK”。responseText 是我希望从 PHP 服务器模型接收到的确切 JSON 数据。

所以我想现在的问题是为什么 collection.fetch 方法将成功结果发送到错误处理程序?我不相信 fetch 回调中这些处理程序的顺序很重要。可以?

4

1 回答 1

16

好的,我找到了获取回调和成功/错误处理程序的参数签名。现在这些设置正确,获取按预期工作。这是工作代码...

  var onDataHandler = function(collection, response, options) {
      console.log('membersview fetch onedatahandler');
      that.render();
  };

  var onErrorHandler = function(collection, response, options) {
      console.log('membersview fetch onerrorhandler');
      alert(response.responseText);
  };

  that.collection = new MembersCollection([]); 
  that.collection.fetch({ success : onDataHandler, error: onErrorHandler });

谢谢你们的回复。我非常需要/感谢您的建议:-)

于 2013-07-26T16:54:12.077 回答