【发布时间】:2013-08-09 16:31:55
【问题描述】:
由于某种原因 this.collection.create() 返回了一个错误,但有趣的是,错误消息看起来像是我刚刚添加到我的集合中的模型。
this.collection.create({
name: $('#big-input').val(),
firstRemark: $('#small-input').val(),
postedBy: window.user.displayName,
twitterHandle: window.user.twittername,
pictureUrl: window.user.profilePic
},{wait: true,
success: function(response){
console.log("success");
console.log(response)
},
error:function(err){
console.log(err)
}
});
这是我在 console.log(err) 之后得到的:
exports.newPost = function(req, res){
console.log("GOT NEW TWEET REQUEST");
var newPost = new Post(req.body)
newPost.dateCreated = new Date();
newPost.save();
res.send(200);
};
感谢下面的答案,我能够打印出我的“真实”错误。如下所示,xhr.responseText 是“OK”,“status”是 200。为什么这个响应触发了成功但触发了错误?
我的收藏中也有一个 parse 方法
parse: function(response){
this.page = response.page;
this.perPage = response.perPage;
this.total = response.total;
this.noofpages =response.noofpages;
return response.posts;
},
【问题讨论】:
-
请求和响应的样子
-
您的模型上有
validate或parse方法吗? -
@kalley 我的收藏有一个解析方法,编辑了我的答案
-
您的服务器需要返回一个带有
200请求的响应正文。看这里:stackoverflow.com/a/14225337/832759