【发布时间】:2017-07-29 10:19:55
【问题描述】:
我正在尝试使用 POST jQuery AJAX 进行简单的登录模式, 但我没有收到来自服务器的任何响应
客户:
$(document).ready(function(){
$("#loginReq").click(function(){
$.post("/login",
{
uname: document.getElementById("username").value,
psw: document.getElementById("password").value
},
function(data, status, jqXHR) {
alert("Data: " + data + "\nStatus: " + status);
});
});
});
服务器:
app.post('/login', function (req, res) {
var username = req.body.uname;
var password = req.body.psw;
var i;
for (i=0; i < users.length; i++)
if (username == users[i].username && password == users[i].password)
{
console.log('found');
//res.send('OK');
//res.sendStatus(200);
res.status(200).send('OK');
break;
}
if (i == users.length)
{
console.log('not found');
res.sendStatus(300);
}
console.log('end of listener');
});
我试过 res.sent、res.end、res.statusCode、res.status.send, 但无论我在客户端尝试什么警报都不会弹出。
(我的目标是得到一个空响应——只有状态码,没有正文, 但没有任何效果)
【问题讨论】:
-
控制台错误服务器和客户端?
标签: javascript ajax node.js express