1
I need to know if the user is logged in through Javascript (jQuery) to run some commands (purely aesthetic). The quickest alternative I could find was to create a hidden input
that is only placed on the page if the user is logged in (verified through PHP) and check by jQuery if that input
exists. But when I put the code below within a $(document).ready()
along with other functions, none of them works anymore, all my jQuery goes to bag. Follows the code:
$(document).ready(function()
{
.
.
.
if ($("#estoulogado").length)
{
$("#email").prop('disabled', true);
if ($("#estoulogado").attr('faoulo') == "fabrica")
{
$("#lojas").prop('disabled', true);
$("#selectdepartamentos").prop('disabled', true);
$("#nome").prop('disabled', true);
};
else if ($("#estoulogado").attr('faoulo') == "loja")
{
$("#fabrica").prop('disabled', true);
$("#selectlojas").prop('disabled', true);
};
};
.
.
.
});
Opening the console (as suggested by Renan) I found a syntax error on this line:
$("#email").prop('disabled', true);
The error is as follows: Uncaught SyntaxError: Unexpected token (
No matter what I put inside the if
, all my code hangs, it doesn’t work. Why does this happen? I also accept a better idea than this to check if the user is logged in.
There’s one missing
)
at the end of the code... shall be});
. Is that your problem?– Sergio
probably a syntax error. open the console and check
– Bruno Calza
Ah, I forgot to put the
)
in the code posted here, I’ll edit, but it’s right in the actual code.– Rafael
If the console indicates an error, add this information to the question. Any error in Javascript causes all scripts to stop after the error in most browsers.
– Oralista de Sistemas
My code all runs normal, but the time I went to add this part, EVERYTHING stopped working.
– Rafael
@Rafael doesn’t cost more than five seconds of your time to press F12 and see if there’s an error in the console. If there is no error in the console, enter this in the question as well, as this is important to determine the cause of the problem.
– Oralista de Sistemas
Sorry Renan, I guess you thought I didn’t want to look at the console. When you sent the comment I was already looking at the console and editing the question. I edited the question and put the full code that is inside the if. Thanks Renan
– Rafael
@Rafael no problem. It’s a syntax error, okay? Some pair of parentheses is not closed properly in your code, and it is not in the statement where the error is shown.
– Oralista de Sistemas