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');
});
via Larsmanson
No comments:
Post a Comment