title: php variable in jquery.ajax request
body: <p>I have a form in a php file that takes user entered values and sends the data into a .txt file.</p>
  
  <p>Now it works fine when the form is filled, the 'submit' button is clicked and the user is sent to a 'confirmation/completed' page, whilst the data received is put into a .txt file.</p>
  
  <p>What i want to do is use ajax and jquery to have the form => completed/confirmation without being sent to the other page.</p>
  
  <p>The problem is the user data is not being transmitted now to the .txt file.</p>
  
  <p>PHP: (confirmation.php)</p>
  
  <pre><code>&lt;?php
    $color = $_POST['color'];
    $fp = fopen('userdata.txt', 'w');
    $valstring = "What Color: " . $color . "\r\n";
    fwrite($fp, $valstring);
    fclose($fp);
  ?&gt; 
  </code></pre>
  
  <p>AJAX/JQUERY: (button clicked from form.php)</p>
  
  <pre><code>$(document).ready(function() {
  
  var cir = {
      load: $('&lt;div /&gt;', { class: 'loading' }),
      contain: $('#contain')
  }
  
  $('input[type="submit"]').on('click', function(e) {
  e.preventDefault();
  
      $.ajax({
          url: 'confirmation.php',
          type: 'POST',
          beforeSend: function() {
              cir.contain.append(cir.load);
          },
          success: function(data) {
              cir.contain.html(data);
          }
      });
  });
  
  });
  </code></pre>
  
  <p>When using the ajax above the userdata.txt file only has the <code>What Color:</code> entered into it. The <code>$color</code> value that the user selected has not been recognised.</p>
  
  <p>I know the code works without the ajax, but i would like to have the ajax (no page refresh) method, if possible.</p>
  
  <p>Thanks in advance for any help.</p>