2016-07-24 42 views
0

嘗試使用我創建的數據在數據庫中登錄,但是當我發佈用戶&傳回調用/ api/login端點時,此端點的網絡響應卡住待處理的請求。檢查響應,並顯示我正在嘗試發送回mongo的有效載荷數據。在開發工具上發佈api端點等待請求

我試圖把$ q延遲諾言在vm.loginuser控制器的調用發生,但無濟於事。即使郵差也不能做一個登錄過程,它也停留在待處理的請求。

角Ctrl鍵:

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)

server.js調用登錄端點:

app.post('/api/login', authController.login); 

模塊:這個console.log在cmd上返回,如果我使用完整的代碼,api會卡在掛起的請求上,不知道代碼是否是w rong或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> 
+0

服務器端是的NodeJS?客戶端和服務器上的console.log方面的成功和錯誤響應,以瞭解其發生的原因。 – maleeb

+0

是的,它的nodejs,一切都只是console.logs(客戶端和服務器端),但沒有一個因爲掛起的調用而返回。如果我在http請求之上添加console.log,將會返回,但低於該值的任何內容都不會返回。 – nCore

+0

在我以前的帖子中添加了登錄模塊代碼。 – nCore

回答

0

您可以測試此爲您角登錄調用

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

}); 
+0

它與我的代碼類似,但什麼我發現如果我在我的module.exports中使用完整的代碼,這是調用卡在掛起的位置,請參閱上面的編輯。不確定是否mongoDB會永遠返回objs或者代碼錯誤,但是它來自一個可以正常工作的教程。 – nCore