you have to make sure you're calling it after the element is on the page (and in the DOM). if it's just stitting in the head by itself, it will run before anything exists on the page. it needs to be inside jQuery's $.ready function (similar to regular onLoad). try this in the <head>:
I do have one follow-up question. Currently, the function loginStatus() is performed after the document is ready/loaded; however, I want the function loginStatus() to run BEFORE the document is loaded. How can I do that?
Thanks for the help. I appreciate the suggestion about firebug. As for the nested binding to a ready event, that was a mistake. Before I found out that the problem was with firebug I was trying different code structures/moving my code around and after I got the code to work I didn't check the syntactic correctness.
The function loginStatus() is js code that via ajax checks if the user is authenticated/logged-in. I have a similar code in php. The reason I am using the js function is certain web-pages of mine do not use any php, thus there is no php authentication status check. That's why I was trying to have loginStatus() run before the entire DOM loads - similar to having it in the header - so the authentication status could be checked on pages where no php is used.
Maybe there is a better way of accomplishing what I want, but I don't know of any other way yet. So, if anyone does please let me know. Thanks.
i think your only option is to run inline script before anything else in the <head>, and i dont think there is an easy way to prevent the rest from loading. you can load a blank page and then based on your ajax login check, populate the body of the blank page with another ajax call.
why not just "include" it on the backend and use the same code?
Currently, in my code when a page is created/display via ajax it does query a php script. When the php script is run/queried I have a php object that checks the user's login status. If the user is not logged-in, the object returns false, ending all functions and echos "User Not Logged-in" error message.
However, I do have webpages that do not use ajax and thus no php script is queried, which results in the php object not running either. Consequently, there is no login status check. That's why I was using the separate js/ajax code on document load to see if the user was logged-in.