ajax - Check user is logged in using Jquery -


Think if someone can help ..

I'm adding some jquery to my site , But I want to restrict some actions depending on whether the user is logged in or not. I'm sure how to find session variables with Jquery.

My initial thought was to call CFC using my check user, JCRAX, and how many rows returned since then, and Work from there. But this is uncertain how to deal with this. At the moment, my code looks like this

  $ .getJSON ('http: // localhost: 8500 / mxRestore / model / mdl_user.cfc? Method = GetUserData and returnFormat = json & queryformat = columns ', {}, function (data) {var isLoggedIn = data.ROWCOUNT;}) if (log in> 0) {// do this} other {warnings (' you Not logged in '); }}  

However, I am getting an error message, which is saying that loggedIn variable is not defined, thinking how to deal with it would be better.

thanks

isLoggedIn variable outside the scope Where you use it, it is only available within getJSON callback, consider there:

  $. GetJSON ('...', {}, function (data) {var isLoggedIn = data.ROWCOUNT & gt; 0; // isLoggedIn now boolean (ifLoggedIn) {// do something} other {alerts ('you login Are not ');}});  

I recommend you return the boolean value to the server rather than highlighting line count .

Function scope:


Comments

Popular posts from this blog

c# - How to capture HTTP packet with SharpPcap -

php - Multiple Select with Explode: only returns the word "Array" -

php - jQuery AJAX Post not working -