Jump to content

Including php file instead of load()


davidb52

Recommended Posts

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...