2017-02-06 7 views
2

リストから投稿を削除しようとしています。 delete関数は、以下に示すdelete関数に連続して渡して実行しています。機能を実行した後にhttp.get要求を再ロードする方法

$scope.go = function(ref) { 
    $http.get("api/phone_recev.php?id="+ref) 
    .success(function (data) { }); 
} 

この機能を実行した後、リストのリストに使用されたhttp.get要求をリロードする必要があります。

$http.get("api/phone_accept.php") 
.then(function (response) { }); 

機能が実行された後。リスト全体が新しい更新リストでリロードされます。このことをする方法はありますか?

+2

はjavascript関数に、削除コールのSUCCESS' 'に' API/phone_accept.php'のための$ HTTP呼び出しを入れて、この関数を呼び出す... –

+0

または、HTTP要求全体を実行する代わりに、delete関数の成功呼び出しでその単一の項目をJSから削除することもできます。 – mehulmpt

答えて

1

@sudheesh Singanamallaは私の問題を解決する関数内で再び同じhttp.get要求を呼び出すことによって言う枚この

$scope.go = function(ref) { 
    $http.get("api/phone_recev.php?id="+ref) 
    .success(function (data) { 
    //on success of first function it will call 

    $http.get("api/phone_accept.php") 
    .then(function (response) { 

    }); 
    }); 
} 
1
function list_data() { 
    $http.get("api/phone_accept.php") 
     .then(function (response) { 
      console.log('listing'); 
     }); 
} 

$scope.go = function(ref) { 
    $http.get("api/phone_recev.php?id="+ref) 
    .success(function (data) { 
      // call function to do listing 
      list_data(); 
     }); 
} 
0

を試してみてください。

$scope.go = function(ref) { 
$http.get("api/phone_recev.php?id="+ref).success(function (data) { 

//same function goes here will solve the problem. 

});} 
}); 
0

関数を非同期で実行し、処理が完了したら戻り値(または例外)を使用するのに役立つサービスを使用できます。いくつかのサービスインサイド

https://docs.angularjs.org/api/ng/service/ $ Q

app.factory('SomeService', function ($http, $q) { 
     return { 
      getData : function() { 
       // the $http API is based on the deferred/promise APIs exposed by the $q service 
       // so it returns a promise for us by default 
       return $http.get("api/phone_recev.php?id="+ref) 
        .then(function(response) { 
         if (typeof response.data === 'object') { 
          return response.data; 
         } else { 
          // invalid response 
          return $q.reject(response.data); 
         } 

        }, function(response) { 
         // something went wrong 
         return $q.reject(response.data); 
        }); 
      } 
     }; 
    }); 

機能のどこかのコントローラで

  var makePromiseWithData = function() { 
       // This service's function returns a promise, but we'll deal with that shortly 
       SomeService.getData() 
        // then() called when gets back 
        .then(function(data) { 
         // promise fulfilled 
//      something 
        }, function(error) { 
         // promise rejected, could log the error with: console.log('error', error); 
         //some code 
        }); 
      }; 
関連する問題