前端---------------: function send_JS_obj() { $.ajax({ url: 'http://localhost:1007/send_JSobj_test?tag=test', type: 'POST', data: JSON.stringify({ name: '张三', age: 20 }), success: function (response) { alert(response.received.name); } }); } 后端------------------------: const http_obj = require("http");//用于产生服务对象 const fs_obj = require("fs");//读写后台文件 const url_tran_obj = require("url");//解释URL const server = http_obj.createServer(function (request, response) { //请求路径处理 var req_str = decodeURI(request.url); var req_head; var POS = req_str.indexOf("?"); if (POS == -1) { req_head = req_str; } else { req_head = req_str.substring(0, POS); } //设置查询对象 var url_obj = url_tran_obj.parse(req_str, true); var Q_obj = url_obj.query; response.writeHead(200, { 'Content-Type': 'application/json;charset=utf-8', 'Access-Control-Allow-Origin': '*' }); //%%%%%%%%%%%%%---------------begin your code if (req_head === '/send_JSobj_test') { console.log("接收到请求:", Q_obj["tag"]); let body = ''; // 监听数据流 request.on('data', chunk => { body += chunk; }); // 数据接收完毕 request.on('end', () => { try { // 解析 JSON 字符串 const jsonData = JSON.parse(body); console.log(jsonData.age); response.end(JSON.stringify({ status: 'success', received: jsonData })); } catch (err) { response.end(JSON.stringify({ ERR: err.toString() })); } }); return; } //%%%%%%%%%%%%%----------------end your code }); server.listen(1007); console.log("Server is running at port 1007...");