0

我是新手angularJS。我已经开始学习 CRUD 操作。我遇到一个问题,当我delete输入时,页面应该reload

$location我也经历$route过。并实施如下:

config

app.config( function ( $locationProvider, $routeProvider ) {
  $locationProvider.html5Mode(true);
    $locationProvider.hashPrefix = '!';

    $routeProvider.when('/', {
        templateUrl: '/views/index.html',
        controller: 'MainCtrl'
    });
    $routeProvider.when('/this',{
        templateUrl: '/views/about.html',
        controller: 'MainCtrl'
    }); 
});

当行动成功时,我写成:

$location.path('/this');

但是当我这样做时,urlhttp://localhost/someapp到更改http://this但页面不会刷新。在这种情况下我该怎么办,请帮帮我?

Edit

这是我的deletion code

$scope.deletecode = function (id) {
    name = '';
    if (confirm("are you sure to Delete the name")) {
        $http({
            method: 'POST',
            url: 'rohit.php',
            data: {
                "name": name,
                "id": id,
                "delete": "true"
            },
        }).
        success(function (data, status, headers, config) {
            alert("data deleted successfully");
            $location.path('/this');
        }).
        error(function (data, status, headers, config) {
            alert("Unable to load data.");
        });
    } else {
        alert("Data deletion cancelled by user ... ");
    }
};

在初始化时,我从 php 文件中获取数据:

$http({
    method: 'GET',
    url: 'test.php'
}).
success(function (data, status, headers, config) {
    $scope.samples = data;
}).
error(function (data, status, headers, config) {
    alert("Unable to load data.");
});

所有数据都存储在$scope.samples其中返回两件事user_idname

4

1 回答 1

0

您的 http 请求正在从您的服务器中删除该项目,但您没有从您的客户端代码中删除它,这就是您的视图没有更新的原因。一旦从服务器中删除,您也想从客户端代码中删除它:

// all items in an array
$scope.items = [item1, item2];
// delete an item
$scope.deletecode = function (id) {
    name = '';
    if (confirm("are you sure to Delete the name")) {
        $http({
            method: 'POST',
            url: 'rohit.php',
            data: {
                "name": name,
                "id": id,
                "delete": "true"
            },
        }).
        success(function (data, status, headers, config) {
            alert("data deleted successfully");
            // at this point, the item has been deleted from your server
            // remove it from $scope.items as well
            // removes 1 item at index idx
            $scope.items.splice(idx, 1);
        }).
        error(function (data, status, headers, config) {
            alert("Unable to load data.");
        });
    } else {
        alert("Data deletion cancelled by user ... ");
    }
};
于 2013-07-10T07:36:39.637 回答