Angle Request $ http is not returning data

0

Javascript code

$http({
   url: "http://app.calculadoradesementes.com.br", 
   method: "POST",
   headers: {
       "Content-Type": "application/x-www-form-urlencoded"
   },
   data: {
       nome: "Rafael", 
       email: "[email protected]", 
       telefone: "82285181"
  }
  }).success(function(data){
       console.log(data);
  }).error(function(data){
      console.log(data);
  });

Data returned

array(0) {
}

PHP file where the request happens

var_dump($_POST);
    
asked by anonymous 17.02.2016 / 19:16

1 answer

2

Yes , the $ http service request is returning data and working as expected.

The returned content is exactly the answer of the endpoint , which seems to me to be the focus of the problem:

var app = angular.module('sampleApp', []);

app.controller('SampleController', function ($scope, $http) {

  $http({
    url: "http://app.calculadoradesementes.com.br", 
    method: "POST",
    headers: {
      "Content-Type": "application/x-www-form-urlencoded"
    },
    data: {
      nome: "Rafael", 
      email: "[email protected]", 
      telefone: "82285181"
    }
  }).success(function(data){
    $scope.result = data;
  }).error(function(data){
    $scope.result = data;
  });
  
});
<script src="//cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.9/angular.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.9/angular-resource.js"></script>
<div ng-app="sampleApp">

  <div ng-controller="SampleController">
    
    {{result}}

  </div>
</div>

The result is the server's complete response. Here is the return header:

HTTP/1.1 200 OK
Date: Wed, 17 Feb 2016 18:26:32 GMT
Server: Apache/2.2.31 (Unix) mod_ssl/2.2.31 OpenSSL/1.0.1e-fips mod_bwlimited/1.4
X-Powered-By: PHP/5.4.45
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: POST
Access-Control-Allow-Headers: X-PINGOTHER
Access-Control-Max-Age: 1728000
Content-Length: 13
Connection: close
Content-Type: text/html
    
17.02.2016 / 19:27