Jump to content

Including php file instead of load()


davidb52
 Share

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.

Edited by thescientist
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...