title: Sending a JavaScript array to PHP via POST
body: <p>I am trying to send a JavaScript array to a PHP file via POST. </p>
  
  <p><strong>JS:</strong></p>
  
  <pre><code>var songlist = ['song1', 'song2', 'song3'];
  
  var sendData = function(){
      var data = songList.join(',')
      $.post('test.php', {data: data}).always(function() {
          window.location = 'test.php';
      });
  }
  sendData();
  </code></pre>
  
  <p><strong>test.php:</strong> </p>
  
  <pre><code>&lt;?php
  $songData = $_POST['data'];
  $songData = explode(',', $songData); 
  print_r(array_values($songData));
  ?&gt;
  </code></pre>
  
  <p>when sendData(); directs me to test.php I get: </p>
  
  <blockquote>
    <p>Notice: Undefined index: data</p>
  </blockquote>
  
  <p>Why doesn't the data variable have any value when I try to print or use it?</p>