JSONファイルから項目を追加したり削除したりするためのアプリケーションを構築しています。 次の問題が発生しました:アイテムを削除するとフロントエンドに反映されます(アイテムは消えます)。ハード・ページの再ロードが2回あります。キャッシュされたものの代わりにPHPファイル。AngularJSでのキャッシュと更新されたJSONファイルの処理
一度だけリロードすると、変更が反映されていないJSONファイルがキャッシュに読み込まれます。
この問題をAngularJSで直接処理する方法はありますか?
$scope.remove = function(array, index){
if($scope.totsselected){
array.splice(index, 1);
$http.post("deleteall.php", {
data : array
})
.then(function(data, status, headers, config) {
$http.get('data/all.json')
.then(function (response) {
$scope.productesgenerals = response.data;
console.log($scope.productesgenerals);
}).catch(function (error) {
});
});
}
)};
そして、私のPHPコード:
はここに私の角度コードです
<?php
$contentType = explode(';', $_SERVER['CONTENT_TYPE']);
$rawBody = file_get_contents("php://input"); // Read body
$data = json_decode($rawBody); // Then decode it
$all = $data->data;
$jsonData = json_encode($all);
file_put_contents('data/all.json', $jsonData);
?>