title: Redirection in an ajax called page
body: <p>I have read quite a bit and I still am missing something.</p>
  
  <p>I have a page that has a button on it.  When you click the button it will call an AJAX function that will then wait and refresh every 5 seconds in waiting for a MySQL database change.  Once the change in the database is made, I would like to take the user to a new page all together.</p>
  
  <p>I have tested the refreshing for the database changes and they work great with echos.  I have tried to use windows.location and the php header redirect.  Neither are working.  </p>
  
  <p>I am not using jquery for the ajax call.  Any help would be greatly appreciated.</p>
  
  <p>Thank you</p>
  
  <p>code:
  index.php</p>
  
  <pre><code>&lt;?php
  session_start();
  $_SESSION = array(
  'player' =&gt; 0
  );
  
  ?&gt;
  &lt;!DOCTYPE HTML&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;script src="ajax.js"&gt;&lt;/script&gt;
  &lt;title&gt;&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  
    &lt;div id="join"&gt;&lt;button type="button" onclick="startGame()"&gt;Throwdown!&lt;/button&gt;&lt;/div&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>rpsjoin.php</p>
  
  <pre><code>&lt;?php 
  include("db.php");
  session_start();
  
  $lastId_q = mysqli_fetch_assoc(mysqli_query($con,'SELECT MAX(id) AS id from game'));
  $lastId = $lastId_q['id'];
  $gameStatus_q = mysqli_fetch_assoc(mysqli_query($con,'SELECT game.game_status FROM game WHERE game.id =' . $lastId));
  $gameStatus = $gameStatus_q['game_status'];
  
  
  
  if ($gameStatus == 2) {
    mysqli_query($con, "INSERT INTO game (game_status, player1_joined) VALUES(1,1)");
    $_SESSION['player'] = '1';
    $playerNumber = $_SESSION['player'];
    $lastId_q = mysqli_fetch_assoc(mysqli_query($con,'SELECT MAX(id) AS id from game'));
    $lastId = $lastId_q['id'];
    $_SESSION['lastId'] = $lastId;
  } elseif ($gameStatus == 1 &amp;&amp; $_SESSION['player'] != 1) {
    mysqli_query($con, "UPDATE game SET player2_joined = 1 WHERE id = " . $lastId);
    $_SESSION['player'] = '2';
    $playerNumber = $_SESSION['player'];
    $_SESSION['lastId'] = $lastId;
  }
  
  $player1_join_q = mysqli_fetch_assoc(mysqli_query($con,'SELECT player1_joined FROM game WHERE game.id =' . $lastId));
  $player2_join_q = mysqli_fetch_assoc(mysqli_query($con,'SELECT player2_joined FROM game WHERE game.id =' . $lastId));
  $player1_join = $player1_join_q['player1_joined'];
  $player2_join = $player2_join_q['player2_joined'];
  
  echo $lastId . "&lt;BR&gt;";
  echo $gameStatus . "&lt;BR&gt;";
  echo $player1_join . "&lt;BR&gt;";
  echo $player2_join . "&lt;BR&gt;";
  
  if ($player1_join == 1 &amp;&amp; $player1_join == $player2_join) {
    echo '&lt;form action="rpsover.php" method="post"&gt;
  
    &lt;button type="submit" name="player" value="1"&gt;Rock&lt;/button&gt;
    &lt;button type="submit" name="player" value="2"&gt;Paper&lt;/button&gt;
    &lt;button type="submit" name="player" value="3"&gt;Scissors&lt;/button&gt;
  
    &lt;/form&gt;';
  
   } else {
     echo "Locating player.  Please be patient";
   }
  
   echo session_id();
  
   ?&gt;
  
  function startGame() {
  
  if (window.XMLHttpRequest) {
    // code for IE7+, Firefox, Chrome, Opera, Safari
    xmlhttp=new XMLHttpRequest();
  } else { // code for IE6, IE5
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
  xmlhttp.onreadystatechange=function() {
    if (xmlhttp.readyState==4 &amp;&amp; xmlhttp.status==200) {
    document.getElementById("join").innerHTML=xmlhttp.responseText;
    setTimeout('startGame()',1000);
  }
  }
  xmlhttp.open("GET","rpsjoin.php",true);
  xmlhttp.send();
  }
  </code></pre>
  
  <p>At the end of rpsjoin.php, instead of showing a form, i want to be redirected to another page.</p>
  
  <p>Yes I know my code is bad and there are test echos in it.</p>
  
  <p>Thank you</p>