2017-04-15 82 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發送回一些數據。

相關問題