Ok, follow these instructions and you are good:
First of all, let's create our node server, I use the Express module to define the HTTP server:
var fs = require('fs'), express = require('express'), app = express(); app.listen(8080); app.use(express.bodyParser()); app.get('/', function(req, res){ var html = fs.readFileSync('index.html'); res.header("Content-Type", "text/html"); res.send(html); }); app.post('/deleteIds', function(req, res){ console.log(req.body.arr[0]); res.json({ success: true }); });
Server request // returns an HTML page that will create a jQuery Ajax request. Here is the contents of the HTML file:
<html> <head> <script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script> <script type="text/javascript"> $.ajax({ url: 'http://localhost:8080/deleteIds', type: 'POST', data: { arr: [ 1, 2, 3] }, success: function(data){ console.log(data); } }); </script> </head> <body> </body> </html>
As you can see, the Ajax request in the html file sent as a POST request with an array as data, the POST function /deleteIds express in the server listens for this and accepts the array using req.body.arr , note that I use app.use(express.bodyParser()); , without this line, we cannot get the body contents from the POST request.
That's all. Hope this helps to understand node + Ajax requests using express, from now on you can run on arr and do what you want with the data.
udidu source share