Brandon
Brandon

Reputation: 23

Error posting a JSON object to nodeJs

I'm trying to post the JSON object "updated" to nodeJS server....and save it to MongoDB using .update.

Javascript in front-end:

$(".save-changes").click( function () {
    var updated = $scope.users;
    $http.post("/update", updated);
});

Node.js:

app.post('/update', function (req, res) {
    MyUser.update( req.updated , function ( err, doc ) {
    err ? res.send( err ) : res.redirect( '/' );
    }); 
});

Upvotes: 0

Views: 41

Answers (2)

Brandon
Brandon

Reputation: 23

It worked when I used "req.body" instead of "req.updated".

Upvotes: 1

BrTkCa
BrTkCa

Reputation: 4783

Try req.body.updated in MyUser.update.

app.post('/update', function (req, res) {
    MyUser.update( req.body.updated , function ( err, doc ) {
    err ? res.send( err ) : res.redirect( '/' );
    }); 
});

Upvotes: 0

Related Questions