title: Using Ajax to create PHP session and echo results
body: <p>I'm using ajax to pass data to a php session in order to save the contents of a js powered shopping cart. Here is the test js code:</p>
  
  <pre><code>//js.html
  
  &lt;html&gt;
  &lt;body&gt;
  &lt;script&gt;   
  function addCart(){
      var brandName = $('iframe').contents().find('.section01a h2').text();
  
      $.post("sessions.php", {"productName": brandName}, function(results) {
               //success alert
      });
  }
  &lt;/script&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>and here is the php code:</p>
  
  <pre><code>//session.php
  &lt;?php
     session_start();
     // store session data
     $_SESSION['productName'] = $_POST['productName'];
  ?&gt;
  
  &lt;html&gt;
  &lt;body&gt;
  
  &lt;?php
     //retrieve session data
     echo "Product Name = ". $_SESSION['productName'];
  ?&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>However what I need is after having saved the data to the session, I want to output it to the user in a mini cart in the sidebar. </p>
  
  <p>When I run <code>js.html</code> it successfully passes the data to <code>sessions.php</code>. However the <code>echo</code> isn't displayed in <code>js.html</code>. If I run <code>sessions.php</code> then the <code>echo</code> displays but isn't in the page I need. </p>
  
  <p>My question is, either via PHP or js, how do I then echo or display this data to the user on the page I need?</p>
  
  <p>Thanks</p>