I have to create a site that looks like Tumblr and Instagram and shows all pictures which are stored in one directory. When you scroll to the end of the page I want to load new pictures but I am a Ajax beginner and dont have a clue how to do this. I think my program will work but I need a PHP variable in the Ajax call. How can I do this?
5
-
possible duplicate of Call php function from javascriptm02ph3u5– m02ph3u52015-09-15 13:08:11 +00:00Commented Sep 15, 2015 at 13:08
-
no i dont need a Variable in Javascript. I have to change the Variable in Ajax everytime I reached the end of the side.FreakyReaper– FreakyReaper2015-09-15 13:11:03 +00:00Commented Sep 15, 2015 at 13:11
-
just echo it into the javascriptDrunkWolf– DrunkWolf2015-09-15 13:12:14 +00:00Commented Sep 15, 2015 at 13:12
-
Show some code. What php variable needs to be used in what ajax call? What have you tried already?MetalMichael– MetalMichael2015-09-15 13:13:56 +00:00Commented Sep 15, 2015 at 13:13
-
Take whatever you need from what you get in your ajax call and update whatever structure you have on your client side. Give an example if you want something more specific.m02ph3u5– m02ph3u52015-09-15 13:13:56 +00:00Commented Sep 15, 2015 at 13:13
Add a comment
|
1 Answer
You can simply echo it into the script the same way you would echo it onto an html page
<script>
...
var phpvar = <?= $php_variable ?>;
...
</script>
3 Comments
Chris Magnussen
Short-tags
<?= should be avoided, as its no longer standard in PHP.DrunkWolf
@ChrisMagnussen Not true, it's actually enabled by default since php 5.4, you're thinking about ASP tags
Chris Magnussen
The docs states that short tags is disabled by default, however the short echo statement
<?= is enabled, so I admit I was partly wrong.. ;)