0
Talk, you guys, all right?
I’m picking up something that I believe should be something simple. I have this little javascript function where according to the level of the user should send to different pages.
For example, if the Session user is level 1, he should do the POST for search_relation2.php, if the user is level 3 send to search_reportario3.php.
With the function I did he ends up sending to the two and the page keeps fighting using one and the other.
What I tried to do was this:
var nivel = <?php echo $_SESSION['nivel']; ?>;
if(nivel = 1){
$('#btn_buscar').click( function(){
$.ajax({
url:'inc/busca_relatorio2.php',
method: 'post',
data: $('#resultado_busca').serialize(),
sucess: function(data){
$('#resultado_busca').val('');
}
});
});
$('#form_data').submit(function(e){
e.preventDefault();
$.ajax({
url:'inc/busca_relatorio2.php',
method: 'post',
data: { busca_data: $('#busca_data').val()}, // sua data chegará como $_POST['busca_data'] no PHP.
success: function(data){
return false; //não vai redirecionar a lugar algum
}
});
});
}
if(nivel = 3){
$('#btn_buscar').click( function(){
$.ajax({
url:'inc/busca_relatorio3.php',
method: 'post',
data: $('#resultado_busca').serialize(),
sucess: function(data){
$('#resultado_busca').val('');
}
});
});
$('#form_data').submit(function(e){
e.preventDefault();
$.ajax({
url:'inc/busca_relatorio3.php',
method: 'post',
data: { busca_data: $('#busca_data').val()},
success: function(data){
return false; //não vai redirecionar a lugar algum
}
});
}
If I debug mine $_SESSION
shows the user logged in and the level of it.
That part of my code is in a file header.php
that contains the entire initial structure of my pages. I imagined that as I already have the session_start()
set at the beginning of the page could use this command. I’m mixing too much (because php is server-side and javascript client-side)?
Thank you, my friends. Have a good day =)
I ended up realizing that my problem is in another function where I return the functions, so even putting this filter will still have errors. But thanks anyway, I’ll better organize my code :)
– Rafael