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
3 Answers
Reset to default 3Definition and Usage The
reload()
method is used to reload the current document. Thereload()
method does the same as the reload button in your browser. By default, thereload()
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();