为什么不是';我的AngularJS post从服务器接收数据吗?

为什么不是';我的AngularJS post从服务器接收数据吗?,angularjs,Angularjs,我在AngularJS中使用以下内容发布到服务器: $http.post('/myurl', {my: "data"}, function(data, status, headers, config) { console.log("returned"); }); 在ChromeDeveloperTools中,服务器正在发回一条200OK状态消息。但是,我的回调从未触发(即,没有打印到控制台)。为什么即使服务器返回OK,AngularJS也不打印消息?您可以试试 return $h

我在AngularJS中使用以下内容发布到服务器:

$http.post('/myurl', {my: "data"}, function(data, status, headers, config) {
      console.log("returned");
});
在ChromeDeveloperTools中,服务器正在发回一条200OK状态消息。但是,我的回调从未触发(即,没有打印到控制台)。为什么即使服务器返回OK,AngularJS也不打印消息?

您可以试试

 return $http({url: '/myurl' , method: "POST",data:my});
您也可以点击F12 chrome控制台查看确切的错误

为了插入结果数据,您可以添加

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

我从未见过这样写的请求,通常您希望执行以下操作:

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


阅读文档
$http.post
使用
然后
方法返回承诺。见@Phill答案。
$http.post('/myurl', {my: "data"})
     .then(function(data) {
        console.log("returned");
     });