我必須向運行localhost:3001的節點服務器發送post請求。我成功地完成了請求並獲取節點服務器中的發佈數據,但數據格式不正確。使用AngularJS&ExpressJS格式化響應JSON數據
AngularJS:
function MyCtrl1($scope,$http,$location) {
$scope.user = { };
$scope.login = function() {
$http.post("http://localhost:3001/login",
$scope.user,
{'Content-Type': 'application/json'}).success(function(result) {
$scope.resultPost = result;
$location.path('/');
}).error(function() {
console.log("error");
});
};
}
的NodeJS:
app.post('/login', function(req,res) {
console.log(JSON.stringify(req.body));
res.end('ok');
});
log : {"{\"username\":\"test\",\"password\":\"pass123\"}":""}
有沒有辦法在這裏得到一個格式化的數據?
我想你想要的JSON.parse(str); – Dylan