title: How to dynamically call a php function in javascript
body: <p>I have an index.php with the following js function:</p>
  
  <pre><code>function returnImageString() {
      return "&lt;?php include 'inc/image.functions.php'; echo getRandomImages(7); ?&gt;";        //This isn't dynamic; this will always return the same images.  How do I fix this?
  }
  </code></pre>
  
  <p>However, when the page loads, the php script is called and the result is added to the source code like this:</p>
  
  <pre><code>function returnImageString() {
      return "images/20.11.A1B9.jpg|images/8.14.47683.jpg|images/19.10.FBB9.jpg|images/21.12.9A.jpg|images/8.11.1474937909.jpg|images/8.15.99404.jpg|images/8.10.jpg|"; //This isn't dynamic; this will always return the same images. How do I fix this?
   }
  </code></pre>
  
  <p>What I want to happen is whenever I call the js function (returnImageString), I want it to call the php function each time (since the php function returns a string of random image locations) instead of having the string hardcoded in the js function.</p>
  
  <p>Can someone point me in the right direction?  Thanks!</p>