2014-07-13 27 views
0

我使用發佈到服務器AngularJS如下:爲什麼我的AngularJS帖子不能從服務器接收數據?

$http.post('/myurl', {my: "data"}, function(data, status, headers, config) { 
     console.log("returned"); 
}); 

在Chrome開發人員工具,服務器發回200 OK狀態消息。但是,我的回調從不觸發(即沒有打印到控制檯)。爲什麼即使服務器返回OK,AngularJS也不打印消息?

+0

閱讀文檔。 '$ http.post'用'then'方法返回承諾。請參閱@Phill答案。 – Miraage

回答

2

我我沒有看到這樣的要求,一般你想要做類似的事情:

$http.post('/myurl', {my: "data"}) 
    .success(function(data) { 
     console.log("returned"); 
    }); 

$http.post('/myurl', {my: "data"}) 
    .then(function(data) { 
     console.log("returned"); 
    }); 
0

你可以嘗試

return $http({url: '/myurl' , method: "POST",data:my}); 

您也可以點擊F12鉻控制檯上看到確切的錯誤

以SERR結果數據可以添加

$http({url: '/myurl' , method: "POST",data:my}).then(
function(result){ 
    console.log(result); 
} 
相關問題