2013-10-26 57 views
1

以下是我的$ http呼叫。请问角有像成功一些功能说以前将实际$ HTTP调用之前执行

$http.post(postUrl, $scope.tempData, { 
     }).success(function(response) { 

       alert(response); 

     }).error(function (errorCode) { 

      alert(errorCode); 
     } 
      ); 
+0

为什么你需要这个功能? –

+0

我想在通话前给页面添加一个加载器,并在调用后成功删除它! –

+0

看看这个小提琴http://fiddle.jshell.net/dBR2r/8/并搜索angularjs ajax微调器。基本思想是在$ htto中的requestInterceptor和responseIntereptor中执行一些操作。另请参阅$ http文档。 – Chandermani

回答

1

角是否有一些功能像成功之前说,这将实际$ HTTP调用之前执行。

快速回答:号

但是你可以在factoryprovider实现该模块并实现任何你想要的逻辑。

这里是例子:

.factory('ajax_post', ['$http', function(_http) { 

    var path = 'src/php/data.ajax.php'; 

    return{ 
     init: function(jsonData){ 

      // do logic here 


      var _promise= _http.post(path, 
       jsonData 
       ,{ 
        headers: { 
         'SOAPActions': 'http://schemas.microsoft.com/sharepoint/soap/UpdateListItems' 
        } 
       } 
       );    
      return _promise; 
     } 

    } 
}]);