rockinaway Posted October 9, 2011 Share Posted October 9, 2011 I have a file, test.php. It has a require statement to include line.php. Now on normal load, I can access the variables set in test.php in line.php. However, I also have an automated reload of line.php using AJAX, where I send a request to access the file and it outputs the same information. HOWEVER, in this case, the variables set in test.php can no longer be access :s .. why is that? I haven't set any data to be passed in the request, but I assume this doesn't have to be done. Quote Link to comment https://forums.phpfreaks.com/topic/248748-accessing-variables-in-a-required-folder-when-using-ajax/ Share on other sites More sharing options...
awjudd Posted October 9, 2011 Share Posted October 9, 2011 Are you trying to use PHP values in your JavaScript call? If yes, then you don't have access to them since JavaScript is all client-side. Your best bet would be to assign the values of your PHP variables to values in your JavaScript. <script type="text/javascript"> var foo = "<?php echo $superSpecialVariable; ?>"; </script> Or I completely misread your post ... ~juddster Quote Link to comment https://forums.phpfreaks.com/topic/248748-accessing-variables-in-a-required-folder-when-using-ajax/#findComment-1277482 Share on other sites More sharing options...
rockinaway Posted October 9, 2011 Author Share Posted October 9, 2011 Kind of, I'll try explaining it better. I have a main page, then in a sidebar, I have a section that is echo'ed out from another PHP page that I have included through a require statement. Now, when the user submits a form, I want to effectively reload that sidebar (and therefore the PHP file associated with it) through AJAX. But my variables don't work anymore, do I have to pass each one through like you've shown? Quote Link to comment https://forums.phpfreaks.com/topic/248748-accessing-variables-in-a-required-folder-when-using-ajax/#findComment-1277484 Share on other sites More sharing options...
awjudd Posted October 9, 2011 Share Posted October 9, 2011 I would try to remove the requirement of the main page being reloaded in order for the sidebar to work properly. Maybe you can extract it out into another php file which they can require? ~juddster Quote Link to comment https://forums.phpfreaks.com/topic/248748-accessing-variables-in-a-required-folder-when-using-ajax/#findComment-1277485 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.