There is ajax request:
$.get('/test', {name : 'Vasya'}); How on server node.js using express library, get the value of name?
There is ajax request:
$.get('/test', {name : 'Vasya'}); How on server node.js using express library, get the value of name?
app.js : const express = require('express') const app = express() app.use(express.json()) app.use(express.urlencoded({extended: false})) app.get('/test', (req, res) => { // Получаем параметры GET-запроса let name = req.query.name console.log(name) // Vasya res.send({user_name: name}) }) app.listen(3000) Run: node app.js , make requests along the path http://localhost:3000/test , you can go through the browser and check (request GET ).
The { name: 'Vasya' } parameters passed during the GET request will be converted to jQuery /test?name=Vasya , and you need to get these parameters (which are in the query query) using req.query . If it were $.post , then through req.body .
GET and POST request is, how they differ, how to send such requests, and then there will be no questions how to handle them. - Peter SamokhinSource: https://ru.stackoverflow.com/questions/847824/
All Articles