1

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.

Paulo Pessoa
  • 2,509
  • 19
  • 30
gentle
  • 151
  • 2
  • 2
  • 14
  • 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 Oct 09 '15 at 02:00
  • I agree with @ExplosionPills since angular has dual binding property or you can just use location.reload() on your function – perseusl Oct 09 '15 at 03:25

3 Answers3

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');
            })
        };
Harish Verma
  • 548
  • 7
  • 17
0

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

Community
  • 1
  • 1
Paulo Pessoa
  • 2,509
  • 19
  • 30
0

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

window.location.reload();
E. G.
  • 1
  • 1