My controller is like this
app.controller("listaTelefonicaController", function ($scope, $http)
Inside of it is my add function
ctrl.adicionarContatos = function (contato) {
contato.telefone = ctrl.formatCel(contato.telefone);
console.log(contato);
var data = JSON.stringify(contato);
$http.post("/contatos.json", {cont: data},{headers: {'Content-Type': 'application/json'}}).then(
function (response) {
console.log("success:" + response);
delete ctrl.contato;
$scope.contatoForm.$setPristine();
return response;
},
function (response) {
console.log(response);
return response;
}
);
// $http({
// url: 'http://127.0.0.1:5500/contatos.json',
// method: "POST",
// headers: {
// 'Content-Type': 'application/json',
// 'Accept': 'application/json'
// },
// data: contato
// })
// .then(function (response) {
// console.log("success:" + response);
// },
// function (response) { // optional
// console.log("Fail:" + response.data);
// });
};
I spent a few hours searching and testing in various ways and all of them appeared the same error
"POST link 405 (Method Not Allowed)"
This file is populated with some data like this below:
{
"nome": "Larissa",
"telefone": "9999-3399",
"cor": "orange",
"data": "2015-04-12T12:53:46.204Z",
"operadora": {
"nome": "GVT",
"codigo": 25,
"categoria": "Fixo"
}
}
GET did everything right, but when I try to do POST it gives this error, I've been looking for a few hours and can not find a way to solve my problem. Enters direct POST error
Thanks for any help!