title: Load php loop with Ajax request (or similar Javascript solutions)
body: <p>I try to figure out how to load just a small piece of data (php loop) with xmlhttp request.</p>
  
  <p>The function I'm using is working perfectly, however I would like to load only php loop which is in the file "gallery.php":</p>
  
  <pre><code>function refreshData(){
  
                    var display = document.getElementById("content");
                    var xmlhttp = new XMLHttpRequest();
  
                    xmlhttp.open("GET", "&lt;?php echo esc_url( home_url( '/' ) ) ?&gt;gallery/");
                    xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
                    xmlhttp.send();
  
                    xmlhttp.onreadystatechange = function() {
                      if (this.readyState === 4 &amp;&amp; this.status === 200) {
                        display.innerHTML = this.responseText;
                      } else {
                        display.innerHTML = "Loading...";
                      };
                    }
                  }
  </code></pre>
  
  <p>I have a post and I'm try to load the images binded to this post. The loop in the gallery.php is here:</p>
  
  <pre><code>&lt;?php $images = get_attached_media( 'image' );
  
              foreach($images as $image) { ?&gt;
                  &lt;div&gt;
                      &lt;img src="&lt;?php echo wp_get_attachment_url($image-&gt;ID,'full'); ?&gt;"/&gt;
                  &lt;/div&gt;
              &lt;?php } ?&gt;
  </code></pre>
  
  <p>I want to load this loop with images after the button is clicked with xmlhttp request, but I do need a help how to request the dynamic data.</p>
  
  <p>Thank you for your help.</p>