Question Details

No question body available.

Tags

javascript node.js express xmlhttprequest es6-modules

Answers (1)

Accepted Answer Available
Accepted Answer
November 29, 2025 Score: 2 Rep: 10,602 Quality: High Completeness: 80%

The problem is not with CJS/ESM, or sending data to the server, but with processing it on the server.

The frontend code's srchData is FormData, so you're sending multipart/form-data request, but on your route handler you apparently don't have any middleware to process it, hence the undefined.

You need to configure and use multer middleware from your code to process such request, for example, .none() method will process text-only multipart form (see multer docs), and you should see the body:

app.post ('/search', multer().none(), async function(req, res, next) {

FormData is usually used to send files, and if you're not sending any files, you might simply use JSON request instead, and app.use(express.json()) from your code will process it:

var srchData = JSON.stringify({like:str, cols: searchWhere});
//...
xhr.setRequestHeader('Content-Type', 'application/json');

xhrx.send(srchData);