2

I'm currently using this in my controller right now: (new to angular don't beat me)

app.controller('userLogin', ['$scope', '$http', '$location', '$route', function ($scope, $http, $location, $route) {
    activeLink = 'userLogin';
    $scope.submitForm = function(valid) {
        if (valid) {
            $http.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded";
            $http.post('/user/login', $('#userLoginForm').serialize())
            .success(function(data) {
                $route.reload();
            });
        }
    }
}]);

Which works fine, when I reload the page the navbar login/create links disappear and is replaced with logout and what not, but my problem is the navbar doesn't reload unless I manually hit CTRL+R

I've tried using $location.path('/'); and $route.reload(); but my navbar doesn't change still unless I manually reload the page.

Datsik
  • 14,453
  • 14
  • 80
  • 121

1 Answers1

2

Would this do the trick? This should completely reload the page to the new address.

window.location.replace("/");

How to redirect to another webpage in JavaScript/jQuery?

app.controller('userLogin', ['$scope', '$http', '$location', '$route', function ($scope, $http, $location, $route) {
    activeLink = 'userLogin';
    $scope.submitForm = function(valid) {
        if (valid) {
            $http.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded";
            $http.post('/user/login', $('#userLoginForm').serialize())
            .success(function(data) {
                window.location.replace("/");
                //$route.reload();
            });
        }
    }
}]);

You could also try to hide the entire document, re-download the content of the document, and replace the content of current page.

$.get("/", function(data){
    $('body').html(data.body); // not sure if data.body will work, sort of guessing here
});

jquery append external html file into my page

Replace the BODY tag to make styles stay in place.

Replace entire HTML document in-place

Community
  • 1
  • 1
HelpNeeder
  • 6,383
  • 24
  • 91
  • 155
  • It does for now, but surely there must be some way to do it without refreshing an entire page? – Datsik Sep 08 '14 at 04:41
  • In theory, you could also try to hide the entire document, re-download the content of the document, and replace content of HTML tag, or document. – HelpNeeder Sep 08 '14 at 04:44
  • http://stackoverflow.com/questions/8277462/jquery-append-external-html-file-into-my-page – HelpNeeder Sep 08 '14 at 04:45
  • @HelpNeeder i need to reload the page after redirecting to page. how to do it in ui-router. i have already tried $state.go('dashboard.places.list', {}, { reload: true}); it is redirecting to the particular view , but not reloads – codelearner Mar 31 '16 at 07:38