0

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 javascript Commented 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. Commented Sep 15, 2015 at 13:11
  • just echo it into the javascript Commented 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? Commented 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. Commented Sep 15, 2015 at 13:13

1 Answer 1

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>
Sign up to request clarification or add additional context in comments.

3 Comments

Short-tags <?= should be avoided, as its no longer standard in PHP.
@ChrisMagnussen Not true, it's actually enabled by default since php 5.4, you're thinking about ASP tags
The docs states that short tags is disabled by default, however the short echo statement <?= is enabled, so I admit I was partly wrong.. ;)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.