這是(使用fetch
)的NodeJS和骨幹獲取
var MyModel = Backbone.Model.extend();
var MyCollection = Backbone.Collection.extend({
url: '/questions',
model: MyModel
});
var coll = new MyCollection();
coll.fetch({
error: function (collection, response) {
console.log('error', response);
},
success: function (collection, response) {
console.log('success', response);
}
});
我的前端代碼,這是(使用app.get
)
app.get('/questions', function (request, response) {
console.log('Inside /questions');
response.writeHead(200, {
'Content-Type': 'text/json'
});
response.write('{test:1}');
response.end();
});
的問題我的後端代碼是,雖然響應如預期的那樣,調用客戶端error
回調。當我刪除行response.write('{test:1}');
時,調用success
回調。任何想法,我可能做錯了什麼?
非常感謝!這確實是個問題。 – Randomblue 2011-12-23 15:32:52
有沒有辦法瞭解有關錯誤的更多信息?在將來,我希望被告知這是JSON是無效的...... – Randomblue 2011-12-23 15:34:36
我不是一個大'node.js'或'backbone'的人。我猜想錯誤響應中有一些信息;如果沒有,我會發布另一個問題,對不起.. – Chad 2011-12-23 15:36:34