我试图将操作号码从客户端发送到服务器端,并收到服务器的响应,但我确实得到了:
angular.js:8467 POST SITE:3000/posts/test 404 (Not Found)
我的代码出了什么问题?
server sided index.js
router.post('/posts/test', auth, function(req, res, next) {
res.json("success");
});
angularjs客户端文件(在邮政服务下):
o.crimePerform = function(post) {
return $http.post('/posts/test', post, {
headers: {Authorization: 'Bearer '+auth.getToken()}
}).success(function(data){
console.log(data);
console.log("performed crime!");
});
}
angularjs客户端文件(执行了acual action)
$scope.performacrime = function(action) {
console.log("performing action number " + action.id);
posts.crimePerform({crimeaction : action.id});
$scope.status = action.name + ' loading...';
$scope.crimeresult = true;
}
回复:angular.js:8467 POST WEBSITE:3000/posts/test 404 (Not Found)
编辑:来自服务器的响应只是一个例子。无论回应是什么,它都不会起作用。
答案 0 :(得分:1)
您的问题似乎与您的角度POST无关。它在服务器端。您的服务器端代码错误输出。
我试过例如:
curl -H“Content-Type:application / json”-X POST -d'{“授权”:“Bearer xyz”}'http://178.62.5.64:3000/posts/test
回来了:
<h1>Not Found</h1>
<h2>404</h2>
<pre>Error: Not Found
at /opt/mean/app.js:48:15
at Layer.handle [as handle_request] (/opt/mean/node_modules/express/lib/rout
er/layer.js:82:5)
at trim_prefix (/opt/mean/node_modules/express/lib/router/index.js:270:13)
at /opt/mean/node_modules/express/lib/router/index.js:237:9
at Function.proto.process_params (/opt/mean/node_modules/express/lib/router/
index.js:312:12)
at /opt/mean/node_modules/express/lib/router/index.js:228:12
at Function.match_layer (/opt/mean/node_modules/express/lib/router/index.js:
295:3)
at next (/opt/mean/node_modules/express/lib/router/index.js:189:10)
at /opt/mean/node_modules/express/lib/router/index.js:191:16
at Function.match_layer (/opt/mean/node_modules/express/lib/router/index.js:
295:3)</pre>
正在调用您的服务器端路由,看起来错误处理正在给出404响应。