我不明白为什么我无法获得我在Angular.js快递中发布的表单数据。
角部分:
$http.post(baseURL+"/search", data).success(function(data, status) {
$scope.results = data;
});明示部分:
app.use(bodyParser.urlencoded({ extended: false }));
app.post('/search', function(req, res){
console.log(req.query, req.body, req.params);
});日志为{}。我不知道我做错了什么。
我也试过:
$http({
method: "POST",
url : baseURL+"/search",
data : {name: 'tete'},
headers: {'Content-Type': 'application/json'}
}).success( function(data){
console.log(data);
});它也不管用。
发布于 2015-08-03 12:56:45
默认情况下,角以JSON的形式发送数据。
$httpProvider.defaults.headers.post //Content-Type: application/json您只包含urlencoded体解析器中间件。您需要包括bodyParser.json()。
app.use(bodyParser.json());
app.post('/search', function(req, res){
console.log(req.body);
});发布于 2015-08-03 13:01:24
看起来,角$http服务以JSON的形式发送数据,而您缺少了适当的bodyParser。
在快车投递路线之前,试着用app.use(bodyParser.json());代替你的app.use(bodyParser.json());。
https://stackoverflow.com/questions/31787724
复制相似问题