我正在使用cordova + angularjs + nodejs(Express) 在android环境中进行测试。现在我尝试通过 $http() 获取一些数据,但总是收到 404 错误(通过下面的警报)。
客户端代码(AngularJs)
$http({
method : 'POST',
url : "http://192.168.1.4:8888/login",
data : ""
})
.success(function(data, status, headers, config) {
alert("success");
alert(data);
})
.error(function(data, status, headers, config) {
alert("error");// <== always gets here
alert(status); // <== 404
}).
finally(function() {
alert("finally");
});
服务器代码(NodeJs+Express)
...
app.get('/login',function(req, res){
res.set({'Content-Type':'application/json','Encodeing':'utf8'});
res.json({name:"jj"});
}) ;
app.listen(8888);
我可以通过访问http://192.168.1.4:8888/login获取json字符串通过Chrome,
我查了很多资料还是没能解决我的问题,有谁可以帮忙吗?
最佳答案
http方法是post,需要是get。
关于javascript - cordova + angularjs + nodejs(Express) $http json 总是得到 404,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30414337/