title: Load php dynamically from a dynamic javascript
body: <p>How can I load my php on my domain using my javascript that was loaded dynamically.</p>
  
  <p>my sample code</p>
  
  <p>sample.html(Client-side)</p>
  
  <pre><code>&lt;div onClick = "getThis()"&gt;&lt;/div&gt;
  </code></pre>
  
  <p>my.js(Client-side)</p>
  
  <pre><code>function getThis(){
  var url = "http://www.sampledomain.com/test.js"
  var script = document.createElement('script');
  script.src = url;
  document.head.appendChild(script); 
  }
  </code></pre>
  
  <p>test.js(Server-side)</p>
  
  <pre><code>$.get("index.php", function(data) {
      alert(data);
  });
  </code></pre>
  
  <p>index.php(Server-side)</p>
  
  <pre><code>&lt;?php 
  
  $_SESSION['user'] = "rob098";
  
  ?&gt;
  
  &lt;script&gt;
  var data = '&lt;?php echo json_encode($_SESSION['user']) ?&gt;';
  &lt;/script&gt;
  </code></pre>
  
  <p>but it doesn't alert any.</p>