localhost : 3001을 실행하는 노드 서버에 게시물 요청을 보내야합니다. 요청을 성공적으로 완료하고 노드 서버에서 게시물 데이터를 가져 오는 중 데이터 형식이 잘못되었습니다.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