martini-contrib / render

Martini middleware/handler for easily rendering serialized JSON, XML, and HTML template responses.
MIT License
245 stars 57 forks source link

Layout reloading every redirection #63

Closed LeaBloodForged closed 7 years ago

LeaBloodForged commented 7 years ago

Hi, I've got some javascript in my layout.html :

    UserName = ""
    $(document).ready(function(){
        if(UserName != ""){
            $("#menu").removeClass("hidde");
            $("#menu").addClass("reveal");
        }
    });

UserName is a global variable that i set in an another html file :

function Login(){
    var log = $("#login").val();
    var mdp = $("#mdp").val();
    var sended = {
        url: '{{.LoginUrl}}',
        type: 'POST',
        data: {'\"log\"': log, '\"mdp\"': mdp},
        success: function(data){
            if(data.Success){
                UserName = data.UserName;
                window.location.replace(data.Url);
            }
            else{
                alert(data.Err);
            }

         }
     };
     $.ajax(sended);
}

I've check the data returned and my UserName is ok with the json return so must be the assignation. But when i do the redirection UserName go back to "" and i can't use it. Is it because the layout is reloaded every time i have a navigation? Thanks for reading and i hope you can help me.

LeaBloodForged commented 7 years ago

Nervermind i've found the answer. When my redirection takes place the layout is reloaded and my global variable is reset.