How to pass the ajax get request data to nodejs GET route?
10,797
jQuery's .ajax()
method sends the data
property as a query string for GET requests, so in your Express code you have to retrieve that data from req.query
instead of from req.body
.
Author by
Ramya S
Updated on June 25, 2022Comments
-
Ramya S almost 2 years
This is my ajax request call
$.ajax({ url: '/refresh', type: 'GET', contentType: "application/json", data: { Name: $("#inputName").val(), Url: $("#inputUrl").val() }, success: function(data) { console.log('form submitted.' + data); } });
This is the GET route in nodejs
app.get('/refresh', function(req, res) { console.log("My data" + JSON.stringify(req.body)); //other operations }
How can i get the data which is passed from ajax call in my js?? Please help!! Thanks a lot!