I cannot make $http.post in Angular, and I am not returned any error

Asked

Viewed 61 times

2

Despite not returning error, the POST seems not to be working.

My code:

// ADICIONA contato AO VETOR contatos
    $scope.adicionarContato = function(contato) {
      contato.data = new Date();
      // REALIZA POST EM contatos, PASSANDO contato COMO OBJETO
      $http.post("http://localhost:80/contatos", contato).then( function (successCallback) {
        delete $scope.contato; //o contato será deletado
        $scope.contatoForm.$setPristine();
        carregarContatos(); //recarrega os contatos
      }, function (errorCallback) {
        $scope.message = "Erro ao postar " + errorCallback.data;
      });
    };

Debugging in the browser looks like everything is ok with the POST, but no data is passed to the file in localhost.

  • 1

    Look at the request by the browser and see if the data is really being sent.

  • The status code is giving OK. In the parameters the object to be passed is correct, but in the answer if the returned JSON does not contain the object.

  • Who is carregarContatos();? The return of the POST is not being interpreted - and is probably being lost.

  • @Snailgalford If the answer is not expected it may be an error in back-end, nay?

  • @LINQ in the back-end is a simple local apache server with static files .json

  • 1

    @Snailgalford And you are trying to make a POST for a JSON file?

  • @LINQ so, no manjo de back-end. What would be the right way? I was following a tutorial of Angular but this part was not very specified. Sorry if it is something very lay.

  • Well, it just doesn’t make much sense to make a POST for a JSON file. It would require an application backend to receive and interpret the request.

  • I will search more about then... I was used to Java and Mysql server. It seems that web is a little different.

Show 4 more comments
No answers

Browser other questions tagged

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