我知道這已被多種方式詢問過,但我的問題似乎與已發佈的問題有所不同。Node Express發送後無法設置標題
我試圖從窗體發送數據到谷歌的Firebase。我有一個使用快遞的節點應用程序。
這裏是我的功能是將數據發送到火力點:
function validateForm() {
async.series([
function (callback) {
var errors = "<strong>The following errors were entered:\n";
var name = $('#name').val();
var story = $('#story').val();
if (name.length < 1) {
errors += "\n-Please enter a valid name";
callback("Please enter a valid name", null);
}
if (story.length < 1) {
errors += "\n-Please enter a valid story";
callback("Please enter a valid story", null);
}
console.log("FInished validating");
callback(null, "finished validating");
}, function (callback) {
firebase.database().ref('stories/' + Date.now()).set({
name: name,
story: story
}, function() {
console.log("Firebase callback");
callback(null, "sent data!");
});
}, function (callback) {
console.log("Finished!");
callback(null, "done")
}
])
}
(增加了一些console.logging爲清楚起見,以確保我有權利的回調)
提交是觸發通過點擊div的樣式看起來像一個按鈕,所以我知道沒有導致問題的表單問題的默認行爲。以下是我在Node中遇到的錯誤。
Error: /Users/keegan/WebstormProjects/hack4health/views/error.hbs: Can't set headers after they are sent. at ServerResponse.OutgoingMessage.setHeader (_http_outgoing.js:356:11) at ServerResponse.header (/Users/keegan/WebstormProjects/hack4health/node_modules/express/lib/response.js:719:10) at ServerResponse.send (/Users/keegan/WebstormProjects/hack4health/node_modules/express/lib/response.js:164:12) at res.render.done (/Users/keegan/WebstormProjects/hack4health/node_modules/express/lib/response.js:956:10) at /Users/keegan/WebstormProjects/hack4health/node_modules/hbs/lib/hbs.js:93:9 at done (/Users/keegan/WebstormProjects/hack4health/node_modules/hbs/lib/async.js:74:20) at /Users/keegan/WebstormProjects/hack4health/node_modules/hbs/lib/hbs.js:88:18 at /Users/keegan/WebstormProjects/hack4health/node_modules/hbs/lib/hbs.js:69:11 at done (/Users/keegan/WebstormProjects/hack4health/node_modules/hbs/lib/async.js:74:20) at /Users/keegan/WebstormProjects/hack4health/node_modules/hbs/lib/hbs.js:64:20
我提供的JS是客戶端 – thekeegs
並有100%defo沒有任何代碼在您的應用程序的其他地方被觸發?我曾經有過類似的情況,但之後它總是在其他地方變得很小。 – John