2017-04-15 71 views
0

基于此解决方案here,我致力于能够从节点服务器接收回应。角度控制器向/从Nodejs服务器发送和接收数据

角控制器

$scope.loginUser = function() { 
     $scope.statusMsg = 'Sending data to server...'; 
     $http({ 
      url: 'http://##.##.##.##/login', 
      method: 'POST', 
      data: user, 
      headers: {'Content-Type': 'application/json'} 
     }) 
} 

服务器的NodeJS

app.post('/login', function(req, res) { 
    console.log('Processing request...'); 
    res.sendFile('/success.html'); 
}); 

怎么能这个例子可以扩展到能够接收响应从服务器返回?

回答

1
$scope.loginUser = function() { 
    $scope.statusMsg = 'Sending data to server...'; 
    $http({ 
     url: 'http://##.##.##.##/login', 
     method: 'POST', 
     data: user, 
     headers: {'Content-Type': 'application/json'} 
    }).then(function(response) { 
     //do something with your response from the server 
     console.log(response.data) 
    }) 
} 

在/后您的路线通常你会从你的控制器将数据发送到可能查询数据库,并通过JSON发送回一些数据。

相关问题