【发布时间】:2019-10-17 22:26:45
【问题描述】:
我在 Nodejs 中创建了一个用于登录的 API。当我尝试对其进行 jquery 发布请求时,它显示 404 Not found,但是当我在浏览器中打开同一页面时,它会找到该文件。
我要请求的代码:
$.post("http://localhost:8000/api/login", {"username": "username", "password": "password"}, function(response) {
console.log(response);
});
我的 API 代码(简化):
app.get("/api/login", function(req, res) {
var username = req.body.username,
password = req.body.password;
//login chechks but basically this is what it returns
res.send({
"error": 0,
"loggedIn": 1
});
res.end();
});
【问题讨论】: