2016-08-12 11 views
0

Imは、クライアントが両面サーバーへの両面からアクション番号を掲示し、サーバからの応答を受け取るしようとしているMEANが、私は入手できますか:ルートポスト文句を言わない作業angularjsは/

angular.js:8467 POST SITE:3000/posts/test 404 (Not Found) 

私のコードで何が間違っています?

サーバー両面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アクションが実行)

$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)

EDIT:サーバーからの応答は単なる例に過ぎません。応答が何であっても、それは動作しません。

+0

あなたはそれを試してみることができますか? –

+0

@KunalKakkadは真剣に?どのように彼はこれをバイバイすることができますか? –

+0

@KunalKakkadはそれをする方法を知らない。 – maria

答えて

1

あなたの問題はあなたの角度のPOSTには含まれていません。それはサーバー側にあります。サーバー側のコードがエラーになりました。

Iは、例えば試み:

カール-H "コンテンツタイプ:アプリケーション/ JSON" -X POSTが-d '{ "許可": "ベアラ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応答を出すようです。

+0

私は何をすべきですか?、私たちは@wakeをチャットできますか? – maria

+0

dosentそれはここにstackoverflowのチャット機能が存在するのですか? – maria

+0

http://chat.stackoverflow.com/rooms/120792/route-post-wont-work-angularjs-mean – maria

関連する問題