jcanker Posted March 6, 2011 Share Posted March 6, 2011 Still pretty new, but just figured this out (and you ol' timers can feel free to slap me for the noob error). I'm posting it here in case someone else runs into the same issue, and to remind ourselves of some of the basics we can easily forget. If you're using jquery, then you're using, $(document).ready(function() { }); and placing your code inside the function here so that it doesn't run until the page is loaded and ready to roll. Any variables you declare in here are NOT global--you'll still have to pass the variable object to functions, etc. I found this because $.getScript wasn't seeing the object literal. Declare the variable /object literal *before* your $(document).ready(function){}) and then it will truly be global: var myObjectLiteral = {}; $(document).ready(function() { //code here, and you can mess with myObjectLiteral all you want now! }); The beatings by veterans may now commence Quote Link to comment https://forums.phpfreaks.com/topic/229806-lil-tip-regarding-jquery-getscript-and-global-vars/ Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.