Angular request does not send post

Asked

Viewed 183 times

0

good night! next...I am making asynchronous requests with Angularjs and it works if use get and params, however if I switch to "post" and "date" it stops sending...I will post here the controller and the page that receives the data:

app.controller('detalhe_carro', ProcessaAlteracao);

ProcessaAlteracao.$inject = ['$http', '$scope'];

function ProcessaAlteracao($http, $scope) {
    $scope.titulo = 'detalhes do carro'
    $scope.tituloCarro = "";
    $scope.descricao = "";
    $scope.ano_carro = "";
    $scope.marca = "";
    $scope.mensagem = "";
    $scope.update = "";
    $scope.requisicao = function () {
          $http( {method: "POST",  url: $scope.update, data: { nome: $scope.tituloCarro }})
                .then(function (response)
                {
                    $scope.retorno = response.data
                    console.log(response);
                }
                , function (response)
                {
                    console.log(response);
                });
    }
}

Now, the page that receives the data:

header('Content-Type: application/json charset=utf-8');
$x = array("info_recebida"=>$_REQUEST);
echo json_encode($x);

anyway , what could have gone wrong in this code??? do not know how to solve this, with post, will not in any way go...

  • Is any error returned ? 404, 500, etc.. ?

  • no errors, I printed the apache_request_headers() variable and did not bring the variable I sent...what you printed was this: Array ( [Host] => localhost [Connection] => Keep-Alive [Content-Length] => 0 [Accept] => application/json, text/Plain, / [Origin] => http://localhost [User-Agent] => Mozilla/5.0 (Windows NT 6.2; Win64; x64) Applewebkit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.90 Safari/537.36 [DNT] => 1 [Referer] => http://local/blog_da_host/site/ [Accept-encoding] => gzip, deflate, br [Accept-Language] => en,en;q=0.8,en-US;q=0.6,en;q=0.4 [Cookie] => PHPSESSID=vgjjj )

  • Good $scope.requisicao is a function, you are calling this function ? Example; $scope.requisicao();

  • I’m calling in html <button ng-click="requisicao()">Change </button>

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.