admin管理员组文章数量:1414614
I'm using AngularJs for my web application and I got problems with my login, the only solution that I found is reloading the page after login, but I need only once, but now is an infinite loop. How can I use Window.location.reload()
only once
Login Method:
.success(function (data) {
$scope.tokengenerated = data.token;
$cookies.put('Username', UsernameValue);
$cookies.put('Token', $scope.tokengenerated);
$location.path("/incidents");
})
I'm using AngularJs for my web application and I got problems with my login, the only solution that I found is reloading the page after login, but I need only once, but now is an infinite loop. How can I use Window.location.reload()
only once
Login Method:
.success(function (data) {
$scope.tokengenerated = data.token;
$cookies.put('Username', UsernameValue);
$cookies.put('Token', $scope.tokengenerated);
$location.path("/incidents");
})
Share
Improve this question
edited Jul 1, 2015 at 17:16
asked Jul 1, 2015 at 1:24
user4229392user4229392
3
- show your code. what is invoking it? – Daniel A. White Commented Jul 1, 2015 at 1:26
-
what's on your
/incidents
view?? – Sudhansu Choudhary Commented Jul 1, 2015 at 1:29 - When I do login and try to go to my Index, angular doesn't detect my cookies at the first load, I need to reload my page – user4229392 Commented Jul 1, 2015 at 1:29
2 Answers
Reset to default 3When loading the page for the first time, do it like this:
wwww.example./incidents?reload=true
Then check if the parameter is there:
if (location.search.indexOf("reload=true") != -1) {
// refresh the page, but no "reload" this time
location.href = "www.example./incidents";
}
Or using Angular.js:
if ($location.search().reload === "true") {
// refresh the page, but no "reload" this time
$location.path("/incidents");
}
Alternatively, you could check for the existence of the cookie you set just before reloading the page. If the cookie is there, do not reload; if it isn't, set it and then reload the page:
if (!$cookies.get("Token")) {
// set cookies, do whatever you need here
// reload it only once
$location.path("/incidents");
}
Try this... It's work!
var refresh = $window.localStorage.getItem('refresh');
console.log(refresh);
if (refresh===null){
window.location.reload();
$window.localStorage.setItem('refresh', "1");
}
本文标签: javascriptHow can I reload once using windowlocationreloadStack Overflow
版权声明:本文标题:javascript - How can I reload once using window.location.reload? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745147780a2644777.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论