Javascript 如何使用$http_post AngularJS+Laravel重定向?

Javascript 如何使用$http_post AngularJS+Laravel重定向?,javascript,angularjs,laravel,Javascript,Angularjs,Laravel,今天早上我发现了$http_方法,它太棒了!但是我有一个问题另一次XD 首先,我发送的内容正确,数据库更新正确,但当我试图用以下代码更新网站时,我有一个错误 $timeout(function() { $location.path('/'); }); 我的密码是 $scope.processForm = function() { $http({ method

今天早上我发现了$http_方法,它太棒了!但是我有一个问题另一次XD

首先,我发送的内容正确,数据库更新正确,但当我试图用以下代码更新网站时,我有一个错误

 $timeout(function() {
                $location.path('/');
              });
我的密码是

$scope.processForm = function() {
                $http({
                    method  : 'POST',
                    url     : 'todos',
                    data    : $.param($scope.formData),  // pass in data as strings
                    headers : { 'Content-Type': 'application/x-www-form-urlencoded' }  // set the headers so angular passing info as form data (not request payload)
                })                
            };
Laravel中my files route.php中的控制器是下一个:

Route::post('todos', function()
    {
        $user = new Nodes;
        $user->name = Input::get("name");
        $user->save();

    });

我不知道如何更新网页时,我发送的形式的内容。。。有什么解决办法吗

在控制器中,将$location作为服务依赖项注入,然后添加一个then函数,该函数确定服务器成功响应时会发生什么

app.controller('ctrlName', ['$scope', '$location', function($scope, $location){
    $scope.processForm = function() {
            $http({
                method  : 'POST',
                url     : 'todos',
                data    : $.param($scope.formData),  // pass in data as strings
                headers : { 'Content-Type': 'application/x-www-form-urlencoded' }  // set the headers so angular passing info as form data (not request payload)
            }).then(function(response){
                //successfully posted data
                $location.path('/');
            }, function(response){
                //error has occurred
            })                
        }; 

}])

谢谢你的回答,我需要这个: