Angular PHP post重定向无法正常工作

时间:2016-11-15 22:02:28

标签: php mysql angularjs redirect post

在表单通过php脚本保存到mysql数据库后,我很难进行角度编辑 这是我的路线:

var app = angular.module('fantasy_App', ['ui-notification', 'ngAnimate', 'ngRoute']); 
                                            // app is using ngAnimate for animations
                                            // app is using ui-notification for notifications



//This configures the routes and associates each route with a view and a controller
app.config(function ($routeProvider, $locationProvider) {
    $routeProvider
        .when('/players',
            {
                controller: 'playersCtrl',
                templateUrl: '../assets/js/libs/angular/views/players.html'
                // controllerAs: 'vm'
            })                  
        .when('/player/:id',
            {
                controller: 'playerCtrl',
                templateUrl: '../assets/js/libs/angular/views/player.html'
            })      
        .when('/add_player',
            {
                controller: 'clubsCtrl',
                templateUrl: '../assets/js/libs/angular/views/add_player.html'              
            })                      
        .when('/clubs',
            {
                controller: 'clubsCtrl',
                templateUrl: '../assets/js/libs/angular/views/clubs.html'
            })
        .otherwise({ redirectTo: '/players' });
});

这是表单正在使用的控制器:

app.controller("clubsCtrl",function($scope,$http,Notification,$location){

。 。

这是通过pghp脚本执行保存的功能:

    $scope.addPlayer = function() 
    {   
        $http.post('add_player.php',
        {
            'selected_club_id' : $scope.selected_club_id, 
            'firstname'        : $scope.firstname, 
            'lastname'         : $scope.lastname, 
            'shirt_number'     : $scope.shirt_number,   
            'position'         : $scope.position, 
            'age'              : $scope.age, 
            'national_team'    : $scope.national_team,              
            'height'           : $scope.height,                 
            'weight'           : $scope.weight,                 
            'price'            : $scope.price,                  
            'ownership'        : $scope.ownership,                                      
            'datum_rodjenja'   : $scope.parent.datum_rodjenja                       
        }               
        ).success(function(data, status, headers, config)
        {           
            //window.location.href = '/players'; 
            //$location.path('players');
            //$location.replace();
            $location.url('/players');

        });
    };  

如您所见,我尝试使用$ location和window.location.href

似乎没有用,页面没有重定向:(

BTW,PHP脚本正常工作,数据被插入到数据库中,没有任何问题。

我做错了吗?

0 个答案:

没有答案