如何调试似乎没有做任何事情的Angular JS $ http.put?

时间:2014-04-18 15:24:56

标签: javascript angularjs

我有这两个功能:

   var getConfigs = function () {
       var defer = $q.defer();
       $http.get('/api/Config/Get')
           .success(function (data) {
               defer.resolve({
                   configs: data,
               });
           });
       return defer.promise;
   }

   var putConfigs = function(config) {
       // When I check here I see config has some values
       $http.put('/api/Config/Put', config);
   }

当我调用getConfigs()时,我看到fiddler中出现了数据,并填充了$ scope.configs。但是,当我调用putConfigs($scope.config);时,我在fiddler中看不到任何内容,并且没有消息传递给我的主机控制器。

有没有人有任何想法可能是错的。有没有其他方法可以调试正在发生的事情,而不是使用Chrome来逐步完成代码和提琴手来观察正在发生的事情?

1 个答案:

答案 0 :(得分:0)

如果这是您的代码范围,那么您没有完成$ http循环。你需要处理响应。

var myPut = $http.put('/api/config/put', config);
myPut.then(function(data){
    //things that should happen when the call is successful go here
}, function(data){
    //things that should happen when the call is not successfful go here
});

如果您正在处理回复,则在任何人都可以帮助您之前,您需要发布该代码。