AngularJs $Https 簡單複寫

//Http services
// =============================================================================
quotePlansController.factory('httpServices',['$http', function(http){
   return {
       //post: function(url,para,config){
    post: function(url,para){
        //---->response here is just response.data
        var httpPromise = http.post(url,para).success(function(response) {
          
        console.log('HttpServices post fliter~~');
        //TODO
       
       
         });
       
        // response here is original,include(data,status,headers),passed by last Promise.
        httpPromise.success = function(fn)
        {
        httpPromise.then(function(response) {
        //console.log('our call back here~!post');
                   //fn(response.data, response.status, response.headers, config);
        fn(response.data, response.status, response.headers);
                 });
               return httpPromise;
           };
       
           return httpPromise;
           
       },
       //get: function(url,config){
       get: function(url){
        //---->response here is just response.data
        var httpPromise = http.get(url).success(function(response) {
           
        console.log('HttpServices get fliter~~');
        //TODO
       
      
       });
        //here response is original,include(data,status,headers),passed by last Promise.
        httpPromise.success = function(fn)
        {
        httpPromise.then(function(response) {
        //console.log('our call back here~!get');
        //fn(response.data, response.status, response.headers, config);
        fn(response.data, response.status, response.headers);
                 });
               return httpPromise;
           };
           
           return httpPromise;
       }  
   }               
}]);
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章