javascript 如何使用angularJS在成功提交后刷新页面
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/33028720/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to refresh the page upon successful submission using angularJS
提问by gentle
Hi how to refresh an html page upon successful submission? I've tried as follows, but its not working.
嗨,如何在成功提交后刷新 html 页面?我试过如下,但它不工作。
$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.
我的项目正在使用 Django 框架。任何的想法?提前致谢。
回答by Harish Verma
Definition and UsageThe
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.
定义和用法该
reload()
方法用于重新加载当前文档。该reload()
方法与浏览器中的重新加载按钮的作用相同。默认情况下,该reload()
方法从缓存中重新加载页面,但您可以通过将 forceGet 参数设置为 true 来强制它从服务器重新加载页面:location.reload(true)。使用此更新的代码。
$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');
})
};
回答by Paulo Pessoa
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.
您可以使用 $route 服务的 reload 方法。在您的控制器中注入 $route,然后在您的 $scope 上创建一个方法 reloadRoute。
$scope.reloadRoute = function() {
$route.reload();
}