So, I have a JQuery Ajax client side. But now I want to handle the ajax post Node.js side.
I have my route and body parser.
app.post('/register', function(req, res){
var firstname = req.body.firstname;
var lastname = req.body.lastname;
var email = req.body.email;
var password = req.body.password;
var confirm_password = req.body.confirm_password;
// Save into my database
...
// Ajax callback return ???
});
In PHP I used json_encode($array) to get an ajax callback success. But how can I do that in node.js ?
JSON.stringify(array)?JSON.stringifyreturns json, just likejson_encodedoes in PHP. It doesn't output anything. Are you asking how to send the json response? It looks like you're using express, so take a look at the docs for the Response. You could use:res.json( array );.