在开发工具上发布api端点挂起请求
Post api endpoint pending request on dev tool
当我发布用户&传递回call/api/login端点,该端点的网络响应停留在挂起的请求上。检查响应,它显示了我试图发送回mongo的有效负载数据。
我尝试在调用发生的vm.loginuser控制器中放入$q defer promise,但没有成功。即使是邮递员也无法完成登录过程——它也会被挂起的请求卡住。
角度控制:
vm.loginUser = function () {
$http.post('/api/login', vm.userlogin).success(function(response){
console.log('redirect to profile');
}).error(function(error){
console.log('err');
});
};
同样,如果我使用.then
而不是.success
,我会得到未定义和localhost:3000/[object%20Object] 404 (Not Found)
的错误"then"
server.js调用登录端点:
app.post('/api/login', authController.login);
模块:这个console.log在cmd上返回,如果我使用完整的代码,api会被挂起请求,不确定代码是否错误,或者mongoDB只是花了很长时间才返回用户名和密码。
module.exports.login = function (req, res){
res.send('test'); // is okay
User.find(req.body, function(err, results){
if(err){
console.log('Fail to login')
}
if(results && results.lenght ===1){
res.json(req.body.username);
}
})
}
html:
<input type="text" class="form-control" id="username"
placeholder="Username" ng-model="vm.userlogin.username">
<input type="password" class="form-control" id="exampleInputPassword1"
placeholder="Password" ng-model="vm.userlogin.password">
<button type="submit" class="btn btn-default"
ng-click="vm.loginUser()">Submit</button>
你能为你的Angular登录调用测试一下吗
$http.post('/api/login', vm.userlogin)
.then(function(success) {
console.log("SUCCESS");
console.log(success);
}, function(err) {
console.log("ERROR");
console.log(err);
})
.finally(function() {
console.log("FINALLY");
});
相关文章:
- JavaScript执行暂时挂起页面
- 是定义的操作系统睡眠/挂起期间setTimeout的行为
- Chrome浏览器“;挂起”;同时在循环中执行AJAX请求
- fullcalendar在删除导致浏览器挂起的多个事件时速度较慢
- 应用将图表转换为图像的jqplot代码时Chrome挂起
- 如何在不使用Internet Explorer的情况下从未挂起的HTML文件执行程序
- MongoDB collection.find()查询挂起
- 使用子字符串方法时应用程序挂起的原因
- 如何在AngularJS中取消挂起的请求
- 从node.js应用程序调用Mongoose Model.save()时挂起
- Chrome,Safari在从本地存储读取时挂起,而Firefox很好
- IE 10 挂起 XMLHttpRequest 6 分钟,然后响应请求(使用 AngularJS 实现 CRSF)
- 挂起 JavaScript 键关闭事件
- HERE 映射 JS API v3 集群提供程序挂起,添加许多数据点
- Ajax 调用挂起在 jQuery 中
- writeln img src将数据提交到外部系统-Firefox和IE挂起
- 在jQuery中,.state()如何确定一个承诺是挂起的、已解决的还是被拒绝的
- 为什么JavaScript中没有挂起回调函数
- SP2007使IE在运行jssor代码时挂起
- 在开发工具上发布api端点挂起请求