Talk to everyone, okay?
I'm catching up with something that I believe should be something simple. I have this little function in javascript where according to the user level I should send to different pages.
Example, if the session user is level 1, you must do POST for search_report2.php, if the user is level 3 send to search_report3.php.
With the function I did, it ends up sending the two pros and the page is fighting with each 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 my $_SESSION
it shows the logged in user and his level.
This part of my code is in a header.php
file that contains the entire initial structure of my pages. I figured that since I already have session_start()
set at the top of the page I could use this command. Is it over-mixing (because php is server-side and javascript client-side)?
Thanks my dear ones. Have a nice day =)