【发布时间】:2026-01-11 15:20:05
【问题描述】:
这是我在 Angular 中的 API 调用:
$http({
method: 'POST',
url: "http://groep6api.herokuapp.com/user",
headers: {'Content-Type': 'application/x-www-form-urlencoded'},
transformRequest: function(obj) {
var str = [];
for(var p in obj)
str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p]));
return str.join("&");
},
data: {username: "testeken3"}
}).success(function (result) {
console.log(result);
});
这是我在 routes/index.js 中的路线:
router.post('/user', function(req, res, next){
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
User.find(function(user){
if(user.username != req.body.username){next(err);}
res.json(user);
});
});
我认为我的 API 调用是正确的,但我的路线需要是什么样的? 这只是没有回应。
【问题讨论】:
标签: angularjs node.js express mongoose