Javascript is not updated instantly on my website

0

I explain, I have a web page that has a menu in the left bar, this menu has several li and ul , these elements should be hidden depending on a variable that gives permission to users, for example :

Usuario 1: [1,2,3,4] <-- Es decir puede visualizar los li con los id : 1,2,3 y 4

Usuario 1: [1,2] <-- Es decir puede visualizar los li con los id : 1 y 2

The system has a login and depending on the user who has certain permissions, it works almost perfect except that when I log out with user 1 and I enter with user 2 the menu is displayed as if it were user 1 (ie with options 1,2,3,4) , this is fixed with a F5 updating the page , but it is wrong that whenever you log in with another user must update the page so that the menu looks correct.

Are the variables of JavaScript kept in cache or the menu remain stored in cache and that is why I must update the page so that it looks correctly?

Here I am attached images

User with multiple privileges

Here I closed the session and entered with another user with fewer privileges, yet the menu is displayed as the previous user:

After doing F5 and updating the page is already shown as it should, from now on it works well:

As I said the only problem is that when you log in with another user the menu is not updated, forces me to update the page.

Here is the order of how are the scripts :

Script to bring the menu from another page

<script> 
$(function(){
  $("#menu").load("menu.jsp"); 
});
</script>

Script to hide the li and ul depending on the permissions of the user

<script>
function permisosMenu() {
      var cadena = <%=permisos%>
      if(!cadena.includes(1) && !cadena.includes(2) && !cadena.includes(3) && !cadena.includes(4) && !cadena.includes(26))
        document.getElementById("bloque1").style.display ="none";

      if(!cadena.includes(5) && !cadena.includes(6) && !cadena.includes(7) && !cadena.includes(8) &&
          !cadena.includes(9) && !cadena.includes(10) && !cadena.includes(11) && !cadena.includes(12) &&
          !cadena.includes(13) && !cadena.includes(14) && !cadena.includes(15) && !cadena.includes(16) && 
          !cadena.includes(27) && !cadena.includes(28))
        document.getElementById("bloque2").style.display ="none";

  if(!cadena.includes(6) && !cadena.includes(7) && !cadena.includes(8) && !cadena.includes(9) 
          && !cadena.includes(10) && !cadena.includes(11) && !cadena.includes(12) && !cadena.includes(27) &&
          !cadena.includes(28))
        document.getElementById("bloque2_op2").style.display ="none";

  if(!cadena.includes(17) && !cadena.includes(18) && !cadena.includes(19) && !cadena.includes(20) )
        document.getElementById("bloque3").style.display ="none";

  if(!cadena.includes(21) && !cadena.includes(22) && !cadena.includes(23))
        document.getElementById("bloque4").style.display ="none";

  if(!cadena.includes(24) && !cadena.includes(25))
        document.getElementById("bloque5").style.display ="none";

  for (var i = 1; i <= 32; i++) {
      if(!cadena.includes(i)){
        //alert("op"+i);
        document.getElementById("op"+i).style.display ="none";
    }
}


}
</script>

This last script permisosMenu() runs in onload in body .

The scripts work perfectly out of that detail, I think it's maybe the order as I execute them or somehow it is stored in cache.

    
asked by angelo1793 26.09.2018 в 17:12
source

0 answers