最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to refresh the page upon successful submission using angularJS - Stack Overflow

programmeradmin4浏览0评论

Hi how to refresh an html page upon successful submission? I've tried as follows, but its not working.

$scope.submit =function(){
        data = {};
        angular.extend(data, $scope.final_data);
        angular.extend(data, { checks : $scope.final_data.checks });
        $http.post('{% url 'submit' %}', data).success(
            function(data){
                alert('succesfully submitted');
                $location.path('{% url 'orc_checkbinning' %}');
            }).error(function(){
                alert('not submitted');
        })
    };

Am using Django framework for my project. Any idea? Thanks in advance.

Hi how to refresh an html page upon successful submission? I've tried as follows, but its not working.

$scope.submit =function(){
        data = {};
        angular.extend(data, $scope.final_data);
        angular.extend(data, { checks : $scope.final_data.checks });
        $http.post('{% url 'submit' %}', data).success(
            function(data){
                alert('succesfully submitted');
                $location.path('{% url 'orc_checkbinning' %}');
            }).error(function(){
                alert('not submitted');
        })
    };

Am using Django framework for my project. Any idea? Thanks in advance.

Share Improve this question edited Oct 9, 2015 at 2:30 Paulo Pessoa 2,56921 silver badges30 bronze badges asked Oct 9, 2015 at 1:58 gentlegentle 1512 gold badges2 silver badges14 bronze badges 2
  • 2 Rather than refresh the page or anything like that you could probably just update it with the new data by updating your viewmodel/scope – Explosion Pills Commented Oct 9, 2015 at 2:00
  • I agree with @ExplosionPills since angular has dual binding property or you can just use location.reload() on your function – perseusl Commented Oct 9, 2015 at 3:25
Add a ment  | 

3 Answers 3

Reset to default 3

Definition and Usage The reload() method is used to reload the current document. The reload() method does the same as the reload button in your browser. By default, the reload() method reloads the page from the cache, but you can force it to reload the page from the server by setting the forceGet parameter to true: location.reload(true).

Use this updated code.

$scope.submit =function(){
        data = {};
        angular.extend(data, $scope.final_data);
        angular.extend(data, { checks : $scope.final_data.checks });
        $http.post('{% url 'submit' %}', data).success(
            function(data){
                alert('succesfully submitted');
                   $scope.reloadPage = function()                                                
                   {
                     $window.location.reload();
                   }
                }).error(function(){
                    alert('not submitted');
            })
        };

I think the best, is update the scope with the data submited, but
If you really wants refresh the page, try this:

You can use the reload method of the $route service. Inject $route in your controller and then create a method reloadRoute on your $scope.

$scope.reloadRoute = function() {
   $route.reload();
}

SO post

I used this in my onSubmit method in my ponent (after clearing the form and giving success message):

window.location.reload();
发布评论

评论列表(0)

  1. 暂无评论