我有一个要读入对象的模拟 json 文件。我的代码如下所示:
m = require('mithril');
/* .. snip .. */
var foo = m.prop([]);
m.request({
method: 'GET',
url: './foo.json',
unwrapSuccess: function (a, b) {
console.log("success");
},
unwrapError: function (a, b) {
console.log("error");
}
}).then(function (a) {
// fill in foo
console.log("object filled");
});
代码总是只unwrapError
打钩。
真正让我困惑的是这两件事:
- 请求成功 - 我可以在 Chrome 的开发工具中看到它。没有任何访问错误的迹象;
- 错误钩子接收到的第一个参数是我所期望的 JSON;第二个参数是对应的 XMLHttpRequest 对象,没有任何错误指示。
因此,与文档相反,响应对象不包含告诉我发生了什么的“错误”属性。
我究竟做错了什么?