I don’t quite understand what you want. Do you want to use variables made in PHP by JS? Without using PHP in the middle? So I think you want to use Ajax.
Basically I’ve done an old function to make a request Ajax. You can use them:
function Get(t,e,n){var s=new XMLHttpRequest;s.onreadystatechange=function(){4==s.readyState&&200==s.status?(e(s.responseText),s=void 0):s.status>=500&&(s=void 0,n(0))},t+=t.indexOf("?")>-1?"&tsmp="+Date.now():"?tsmp="+Date.now(),s.open("GET",t,!0),s.send()}
function Post(t,e,n,o){var s=new XMLHttpRequest;s.onreadystatechange=function(){4==s.readyState&&200==s.status?(n(s.responseText),s=void 0):s.status>=500&&(s=void 0,o(0))},t+=t.indexOf("?")>-1?"&tsmp="+Date.now():"?tsmp="+Date.now(),s.open("POST",t,!0),s.setRequestHeader("Content-type","application/x-www-form-urlencoded"),s.send(e)}
(b, well, I’ve taken pills before)
And then, well, you need a PHP file that echoes some user value. As an example:
<?php (...) echo Usuario["privilegio"];?>
Then using the function Get
above you can take this value that will come out of the PHP file. Are required 3 arguments: [URL do arquivo]
, [função de sucesso]
and [função de erro]
Get("http://localhost:8000/valor.php",function(e){
alert("Valor: "+e);//alerta "Valor: Usuario[\"privilegio\"]" do arquivo PHP
if(parseInt(e)==0){//se o privilégio do usuário é igual à 0
//yay
}
},function(){
alert("Falhou na requisição. Pode ser um delay?")
}
)
Remember to make the same condition if
to the administrator’s action file.
<script> your code goes here. </script>
– Gabriel Rodrigues
@Highlander I know it’s in the inside
<script>
...rsrsrs, but is done in the same structure as my php example above?– Tiago
And how will you make the JS know if you are admin or not?
– Maniero
@bigown when the person logs in gets registered in the variable
loginPermissoes
.– Tiago
The JS code does not work, the logic of the two languages is completely different. PHP creates text to send to the browser, JS manipulates the existing page through the GIFT. But how does JS know the value of this variable? needs to know how it intends to solve this. Depending on the case, it makes no sense to solve this in JS. If it makes sense, maybe it’s not just a case of messing with this.
– Maniero
I could even answer how to do the display but I would need to know where the information comes from whether it’s admin or not. Without this, it is an abstract problem and not real, then it is difficult to answer.
– Maniero