2015-06-25 42 views
0

這是本地主機服務器上的expressJS代碼。表示沒有收到來自angularjs的數據

var express = require('express'); 
var path = require('path'); 
var cookieParser = require('cookie-parser'); 
var bodyParser = require('body-parser'); 
var app = express(); 

app.use(express.static("../../03 AngularJS/99_Motorcycle_Angular")); 
app.use(bodyParser.json()); 
app.use(bodyParser.urlencoded({extended: false})); 

app.post("/cut_tag", function (req, res) { 
    console.log("Data Coming.."); 
    console.log(req.body); 
    console.log(JSON.stringify(req.body)); 
    res.send("OK"); 
}); 
module.exports = app; 

這是我測試發送數據到本地主機服務器的angularjs代碼。 (4款)

$http.post('http://localhost:3000/cut_tag',"54") 
.success(function (data) {alert(data);}); 

$http.post('http://localhost:3000/cut_tag',{t:"54"}) 
.success(function (data) {alert(data);}); 

$http.post('http://localhost:3000/cut_tag',{'t':"54"}) 
.success(function (data) { 
    alert(data); 
}); 

$http({ 
method: 'POST', 
url: 'http://localhost:3000/cut_tag', 
data: "54", 
headers: { "Content-Type": "application/json" } 
}).success(function (data) { 
    alert(data); 
}); 

//The Output on Console is 
//Data Coming.. 
//{} 
//{} 

//Data Coming.. 
//{} 
//{} 

//Data Coming.. 
//{} 
//{} 

//Data Coming.. 
//{} 
//{} 

和Angular App alert(「OK」); 但我不知道爲什麼console.log(req.body)沒有數據。感謝您的幫助。現在

回答

0

,我可以解決的附加限制這個問題的數據大小張貼

app.use(bodyParser.json({limit: '50mb'})); 
app.use(bodyParser.urlencoded({limit: '50mb', extended: false})); 
相關問題