2017-04-15 12 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を通じていくつかのデータを送り返すためにあなたのコントローラからデータを送信されるだろう。

関連する問題