The node express's bodyParser can't get the parameter in the GET request
If you are issuing a GET request, the URL parameters are not part of the body, and thus will not be parsed by the bodyParser middleware.
To access the query parameters, just reference req.query
You can access your data for get request in server-side by using req.query.key
and req.query.value
.
In order to get params from bodyParser
you must use POST
not GET
. Your ajax request and server calls must both use POST
.
http://expressjs.com/api.html#req.body
app.post('/update', function(req, res){ showParam(req, res);});$.ajax({ url: '/update', type: 'POST', data: { "key": key, "value": value }, success: function (data, err) { } });
To get the GET
params, use the url
module and use query = url.parse(req.url, true).query
. query
will contain an object with the values accessible via query.foo