Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

573
Vistas
$http post with angular gives error: possibly unhandled rejection

I've just managed to get my $http post working over Angular. It does what it needs to do, but when I post the data and then refresh the page it gives this error in my console:

Possibly unhandled rejection: {"data":null,"status":-1,"config":{"method":"POST","transformRequest":[null],"transformResponse":[null],"jsonpCallbackParam":"callback","url":"/insert","data":

This is my Angular post call:

app.controller('ContactCtrl', function($scope, $http){
  $scope.formModel = {};
  $scope.onSubmit = function(){
  $http.post('/insert', $scope.formModel)
  console.log('success');
  };
});

And this is my server call in Express.js to my MongoDB:

router.post('/insert', function(req, res, next){
  var item = {
    name: req.body.name,
    adress: req.body.adress,
    postal: req.body.postal,
    city: req.body.city,
    email: req.body.email,
    phone: req.body.phone,
    quotation: req.body.quotation,
    message: req.body.message
};

var data = new UserData(item);
data.save();
console.log('Item inserted');

});
about 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

try with

var BACKEND_URL = "http://whatever:port";
var postData = angular.toJson($scope.formModel, true);
$http.post(BACKEND_URL + '/insert', postData);

and on the backend, either use res.sendStatus(200); after mongo save operation or modify like below.

.save(function(err, result) {
    if (err) throw err;

    if(result) {
        res.json(result)
    }
})
about 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda