I am trying to send data to the server with the Ajax POST function, and then receive it at the server side with Node.js (and then manipulate it there) but the only problem is that I am unable to find any function at the Node.js side to allow me,accomplish this.I would really like it if you guys could help me out on how to do this as even related threads, I visited on many websites were not very helpful.
Thanks
It will be much easier for you to use some Node-framework like express, to handle all that routes and requests.
You can install it and body-parser module with these commands:
npm install express --save
npm install body-parser --save
Visit express API References to find out more: http://expressjs.com/4x/api.html
var express = require('express');
var bodyParser = require('body-parser');
var app = express();
app.use(bodyParser.json());
// Handle GET request to '/save'
app.get('/save', function(req, res, next){
res.send('Some page with the form.');
});
// Handle POST request to '/save'
app.post('/save', function(req, res, next) {
console.log(req.body);
res.json({'status' : 'ok'});
});
app.listen(3000);
Inside your app.post() route you can get access to any post data using req.body. So your S_POST["name"] will be req.body.name in this case.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With