Jump to content

Accessing variables in a required folder when using AJAX


rockinaway

Recommended Posts

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.