Retrieve form value after redirecting to different URL in node.js

Suppose i have a form which asks for username only and has a button called login. The URL for the current scenario is localhost:8080/beforelogin .

Once I click on login, the form redirects to localhost:8080/loginsuccess . I have to show the message WELCOME USER (the username was entered on localhost:8080/beforelogin) .

I can fetch username but because of the page refresh (redirect to different URL), I cannot show it on different URL.

My code on client side

$('.login').on('click', function()     // login is class of button Login
    {
        document.location.href = "/loginsuccess";    
        var username=$('.username_entered').val());   // username_entered is class username entered before login.
        $('.user-name-to-publish').html(username);    // user-name-to-publish is the class where i have to publish username entered before login
    });

I can explain more if I am not clear.

Ok one way of doing this would be passing the entered username along as a parameter in the url.

$('.login').on('click', function()     // login is class of button Login
    {
        var username=$('.username_entered').val());
        document.location.href = "/loginsuccess?username=" + username;
    });

and then fetch the username in the loginsuccess page. Check this blog for more info:

http://www.sitepoint.com/url-parameters-jquery/

Another way would be to post it to the server and let the server redirect your user to the loginsuccess page and then have the server send the username.