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?
Asked
Active
Viewed 88 times
0
-
possible duplicate of [Call php function from javascript](http://stackoverflow.com/questions/7165395/call-php-function-from-javascript) – m02ph3u5 Sep 15 '15 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 Sep 15 '15 at 13:11
-
just echo it into the javascript – DrunkWolf Sep 15 '15 at 13:12
-
Show some code. What php variable needs to be used in what ajax call? What have you tried already? – MetalMichael Sep 15 '15 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 Sep 15 '15 at 13:13
1 Answers
1
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>

DrunkWolf
- 994
- 1
- 6
- 18
-
Short-tags `=` should be avoided, as its no longer standard in PHP. – Chris Magnussen Sep 15 '15 at 13:17
-
@ChrisMagnussen Not true, it's actually enabled by default since php 5.4, you're thinking about ASP tags – DrunkWolf Sep 15 '15 at 13:18
-
1The docs states that short tags is disabled by default, however the short echo statement `=` is enabled, so I admit I was partly wrong.. ;) – Chris Magnussen Sep 15 '15 at 13:23