javascript 客户端:
let xmlHttp = new XMLHttpRequest();
xmlHttp.open("POST", XMLHttpServerUrl+"/requestapi");
xmlHttp.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
xmlHttp.onreadystatechange = function(e) {
if (this.readyState == 4 && this.status == 200) {
console.log("request succeed.");

在使用XMLHttpRequest从JavaScript客户端发送JSON数据到Node.js服务器时遇到问题,服务器始终返回空响应。原因是服务器端缺少bodyParser.json()中间件,未正确解析HTTP请求体。添加该中间件并设置正确的Content-Type头部后,问题得以解决。
最低0.47元/天 解锁文章
412

被折叠的 条评论
为什么被折叠?



