Good afternoon, I write on Angular js express js (node) on anular I write

$scope.showAlert = function (user) { $scope.ctatus = true; var data = user; $scope.url = 'http://127.0.0.1:3000/api'+'?name='+user.lastName; $http({ method: $scope.method, url: $scope.url, cache: $templateCache }) .then(function(response) { $scope.status = response.status; $scope.data = response.data; console.log(response); }, function(response) { $scope.data = response.data || "Request failed"; $scope.status = response.status; }); }; 

on server

 router.post('/api', function (req, res, netx) { res.json({name : 1}); console.log(req.query); }); 

All that is needed comes to the server, but the answer in the form of json is not returned and I cannot use the sent data in the application. How to make a normal integration of express and angular, well, at least the data from the server could normally pick up, without errors.

  • one
    JSON.parse () and JSON.stringify () did not try to use from the server side? - Den
  • So everything is fine on the server, oh, everything is bad on the client - arseniy mironov
  • As I understand it, you are sending a simple post from the server instead of Jason (from the question). That's where you need to redo it. - Den
  • the answer is res.json ({name: 1}) therefore the answer comes in the format json - arseniy mironov
  • res.json({name : 1}); on res.json(JSON.stringify({name : 1})); try to replace - Den

1 answer 1

The problem is that there is no access (by default) to use the API from third-party resources, so if you have the same problem, read CORS ( http://enable-cors.org/ ) and you will succeed !!!