【发布时间】:2019-03-23 13:44:56
【问题描述】:
当我从客户端向我的 Express 服务器发送 GET 请求时,它会将数据发送到客户端,但我的 XMLHttpRequest 就绪状态为 1,状态为 0,它从不记录响应文本。
客户:
req.onreadystatechange = function() {
console.log(this.readyState);
if (this.readyState == 4 && this.status == 200) {
console.log(this.responseText);
}
};
req.open('GET', url + 'users', true);
req.send();
服务器:
app.get('/users', function(req, res) {
res.send(users);
});
如果有人能告诉我为什么我无法在客户端接收用户数组以及如何解决它。那太好了。
【问题讨论】:
-
确保在 req.open 中使用相对路径。无论如何它应该是 url+"/users"
标签: javascript node.js ajax express get