davidb52 Posted January 27, 2012 Share Posted January 27, 2012 Hello,I'm using this script right now:mainpage.php <?php$mainpage = 'secret';?><a href="#" id="renamegroups">Rename groups</a><div id='renamegroupsl'></div> <script type="text/javascript">$('#renamegroups').click(function(){ $("#renamegroupsl").load("../information/renamegroups.php"); return false;});</script> renamegroups.php <?phpecho $mainpage;?> The problem is that I get this error:Notice: Undefined variable: mainpage in (...)So how could I include a file with ajax / jquery (because if I include the file this will work and the error won't show up) Thanks! Link to comment Share on other sites More sharing options...
thescientist Posted January 27, 2012 Share Posted January 27, 2012 because by the time jquery makes the load call, the PHP in mainpage has already executed and $mainpage is longer defined (and doesn't exist within the context of mainpage.php anymore). you have to realize that PHP and Javascript are server side and client side, respectively. Server side code runs first, then client side code. if you could explain the intent of your functionality, then we can probably suggest a for you to do what you are looking for. Link to comment Share on other sites More sharing options...
dsonesuk Posted January 27, 2012 Share Posted January 27, 2012 to send the value to renamegroups you would use $("#renamegroupsl").load("renamegroups.php?mainpage=<?php echo $mainpage; ?>"); then in renamegroups.php read the GET value <?php$mainpage="";if(isset($_GET['mainpage'])){$mainpage=$_GET['mainpage'];}echo $mainpage;?> Link to comment Share on other sites More sharing options...
davidb52 Posted January 28, 2012 Author Share Posted January 28, 2012 @thescientistThanks for the explanation now I know that it never ever is possible. @dsonesukThanks for your help I would also solve it that way. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.