Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

571
Views
$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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!