CORS error XMLHttpRequest can not load [closed]

1

I have the following problem:

  

XMLHttpRequest can not load

Whenever I send data from Angular to PHP .

My PHP looks like this:

header('Access-Control-Allow-Origin: *');
header("Access-Control-Allow-Methods: GET, POST, OPTIONS, PUT, DELETE");
header("Access-Control-Allow-Headers: X-API-KEY, Origin, X-Requested-With, Content-Type, Accept, Access-Control-Request-Method");

$_POST = json_decode(file_get_contents('php://input'), true)

$name = $_POST['name'];
echo json_encode($name);

The angle is right ..

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

app.controller('mycontroller', function($scope, $http){
    $scope.sendPost =  function (send) {
        $http.post('http://localhost/meuSite/www/server/sendemail.php', send).then(function success(data){
            console.log(data);
            console.log(data.data);
        }).then(function error(err){
            if(err){
                console.log(err);
            }
        });
    }
}); 

And I put a .htaccess file in the root with this content:

header set Access-Control-Allow-Origin "*"

For now, everything is localhost . The front I'm running with http-server and back with apache do xampp .

    
asked by anonymous 31.01.2017 / 17:19

0 answers