Skip to content

Instantly share code, notes, and snippets.

@leonardocouy
Last active November 12, 2015 09:41
Show Gist options
  • Save leonardocouy/65f6a751ed9598164831 to your computer and use it in GitHub Desktop.
Save leonardocouy/65f6a751ed9598164831 to your computer and use it in GitHub Desktop.
Post JSON with PHP
//Coloca isso no teu arquivo PHP
<?php
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, POST');
header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Access-Control-Allow-Origin"); // NOVA LINHA
$request = json_decode(file_get_contents('php://input'));
echo $request->nome
// MANIPULE O RESULTADO COMO QUEIRA! VIA O $request
?>
.controller('TesteCtrl', function($scope, $http){
$scope.data = {}
$scope.confirmar = function(){
var data = {
'nome' : $scope.data.nome,
};
$http.post("http://localhost/test/", {nome : $scope.data.nome}).then(function (res){
console.log(res.data)
});
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment