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.

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

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?

Archived

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

×
×
  • 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.