2016-04-23 105 views
0
發出後

無法設置頁眉發出後 得到錯誤無法設置頁眉..我怎樣才能解決這個錯誤無法設置頁眉後發送。在節點JS

app.post('/post', function (req, res) { 

var diagnosis; 

var obj = req.headers['data']; 

var temp = JSON.parse(obj) 
console.log("Received body data:"); 
console.log(obj); 

MongoClient.connect(url, function (err, db) { 
    assert.equal(null, err); 
    insertDocument(temp, db, function() { 
     db.close(); 
    }); 
}); 


var insertDocument = function (obj, db, callback) { 
    try {    
     console.log(obj); 
     db.collection('diagnosis').remove(); 
     db.collection('diagnosis').insertOne(obj, function (err, result) { 
      assert.equal(err, null); 
      console.log("Inserted a document into the Diagnosis collection."); 
      callback(); 
     }); 
     res.send("Inserted a document into the Diagnosis collection."); 
    } catch (err) { 
     console.log(err); 
    } 
}; 

res.send('Hello POST');}) 

我的功能調用API爲

$scope.post = function() { 

       var diagnosis = $scope.Treatments; 


      var httpRequest = $http({ 
       method: 'POST', 
       url: '/post', 
       headers: { 
        'Content-Type': 'application/json; charset=utf-8', 
        'data': JSON.stringify($scope.Treatments) 
       }, 

      }).success(function (data, status) {      
      }); 
     }; 
+1

刪除res.send('Hello POST');最後。 –

回答

1

此錯誤表示:您已發送回覆。我想讓你讀this。在處理請求後,當您向您發送響應時,連接將被丟棄。