【发布时间】:2021-07-30 11:49:00
【问题描述】:
我是 backend 的新手,我在通过 vanilla ajax 将数据发送到我的快速服务器时遇到了一些麻烦。
请告诉我哪里出错了
我的 ajax 请求:
var xhttp = new XMLHttpRequest();
xhttp.onload = function() {
};
xhttp.open("POST", "http://localhost:8080", true);
xhttp.withCredentials = true;
xhttp.send("name=abhishek");
我的快递服务器:
var express = require('express');
var cors = require('cors');
var app = express();
app.use(cors({
credentials:true,
origin:'http://127.0.0.1:5500'
}));
var PORT = process.env.PORT || 8080;
const bodyParser = require('body-parser');
app.use(bodyParser.urlencoded({extended: true}));
app.use(bodyParser.json());
app.get('/', function(req, res){
console.log(req.query);
});
app.listen(PORT, function(err){
if (err) console.log(err);
console.log("Server listening on PORT", PORT);
});
我在控制台中收到一个空对象作为输出
【问题讨论】: