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.
Look at the request by the browser and see if the data is really being sent.
– Jéf Bueno
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.
– Lucas Rosa
Who is
carregarContatos();
? The return of the POST is not being interpreted - and is probably being lost.– OnoSendai
@Snailgalford If the answer is not expected it may be an error in back-end, nay?
– Jéf Bueno
@LINQ in the back-end is a simple local apache server with static files
.json
– Lucas Rosa
@Snailgalford And you are trying to make a POST for a JSON file?
– Jéf Bueno
@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.
– Lucas Rosa
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.
– Jéf Bueno
I will search more about then... I was used to Java and Mysql server. It seems that web is a little different.
– Lucas Rosa