Loc*_*ost 9 error-handling fetch backbone.js
下面骨干collection.fetch代码火灾,由于某种原因,错误,然后跳转到错误处理程序(如预期),但我真的不知道的ErrorHandler PARAMS是什么.错误触发时,模型,xhr和选项参数未定义.我究竟做错了什么?
var onErrorHandler = function(model, xhr, options) {
alert(options);
};
that.collection = new MembersCollection([]);
that.collection.fetch({ success : onDataHandler, error: onErrorHandler, dataType: "jsonp" });
Run Code Online (Sandbox Code Playgroud)
@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]
Run Code Online (Sandbox Code Playgroud)
status = 200,文本为"OK".responseText是我期望从PHP服务器模型接收的确切JSON数据.
所以我想现在问题是为什么collection.fetch方法将成功结果发送给错误处理程序?我不相信fetch回调中的那些处理程序的顺序很重要.可以?
Loc*_*ost 16
好的,我找到了fetch回调和成功/错误处理程序的params签名.现在这些设置正确,fetch正在按预期工作.这是工作代码......
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 });
Run Code Online (Sandbox Code Playgroud)
谢谢你们的回复.我非常需要/欣赏你的建议:-)
归档时间: |
|
查看次数: |
19300 次 |
最近记录: |