title: AJAX post data to PHP file and redirect to the same file to echo post data
body: <p>I have a php file with a bunch of <code>&lt;a&gt;&lt;/a&gt;</code> elements containing user names. Upon clicking one of these links, the link's <code>data</code> attributes are stored and posted to the second php file via AJAX. However, once I redirect to that file, the value I posted is not being displayed, instead I get the error: <code>Undefined index userid</code>. </p>
  
  <p>Here's my code:</p>
  
  <p>Index.php</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html lang="en"&gt;
  &lt;head&gt;
    &lt;meta charset="UTF-8"&gt;
    &lt;title&gt;Post Test&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  
  &lt;a href="#" class="user-name" data-user-id="1" data-render-view="users.php"&gt;User 1&lt;/a&gt;
  &lt;a href="#" class="user-name" data-user-id="2" data-render-view="users.php"&gt;User 2&lt;/a&gt;
  &lt;a href="#" class="user-name" data-user-id="3" data-render-view="users.php"&gt;User 3&lt;/a&gt;
  &lt;a href="#" class="user-name" data-user-id="4" data-render-view="users.php"&gt;User 4&lt;/a&gt;
  &lt;a href="#" class="user-name" data-user-id="5" data-render-view="users.php"&gt;User 5&lt;/a&gt;
  
  &lt;script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"&gt;&lt;/script&gt;
  &lt;script type="text/javascript"&gt;
  $('.user-staff').on('click',function(){
    var userid = $(this).data('user-id');
    var renderView = $(this).data('render-view');
  
    $.ajax({
      url: "users.php",
      type: "POST",
      data: {userid:userid},
      success: function(data, textStatus, jqXHR){
        window.location = renderView;
      },
      error: function (jqXHR, textStatus, errorThrown){
        alert('Error!')
      }
    });
  });
  
  &lt;/script&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Users.php</p>
  
  <pre><code>&lt;?php
  
  $userIdExchanged = $_POST['userid'];
  
  echo '&lt;h1&gt;user profile page&lt;/h1&gt;';
  echo $userIdExchanged; //Nothing is outputted here.
  
  ?&gt;
  </code></pre>