title: Send JavaScript array to PHP array via jQuery Ajax
body: <p>I'm trying to send a JavaScript array via jQuery Ajax to a new PHP array:</p>
  
  <pre><code>var heart = [31,32,33,34,35,36,37,38,39,42,43];
  
  $('#find_btn').click(function(){
      $.ajax({
          type: "POST",
          url: 'scripts/get_specimens_system.php',
          data: {
                  system: heart,
          },
          success: function(data) {
              $('#search_list_container').html(data);
          }
      });
  });
  </code></pre>
  
  <p>In the PHP script I have the following before a MySQL query:</p>
  
  <pre><code>$system = array($_POST['system']);
  </code></pre>
  
  <p>If I hardcode the data in <code>heart</code> like:</p>
  
  <pre><code>$system = array(31,32,33,34,35,36,37,38,39,42,43);
  </code></pre>
  
  <p>the query works OK. What am I doing wrong?</p>
  
  <p>In an attempt to simplify the question I have left out the fact that I'm setting the JS array to <code>var system</code> via <code>system = $(this).attr('data-system');</code></p>
  
  <p>Where the data-system is set to the arrays like:</p>
  
  <pre><code>$('#sub_category_box_systems').html("&lt;a class='sub_category_link' href='#' data-subcat-type='system' data-system='" + brain + "'&gt;Brain&lt;/a&gt;&lt;br /&gt;&lt;hr&gt;&lt;a class='sub_category_link' href='#' data-subcat-type='system' data-system='" + nerves + "'&gt;Nerves&lt;/a&gt;&lt;br /&gt;&lt;hr&gt;&lt;a class='sub_category_link' href='#' data-subcat-type='system' data-system='" + cerebellum + "'&gt;Cerebellum&lt;/a&gt;");
  </code></pre>
  
  <p>Now if I alert <code>system</code> just before the AJAX statement the alert shows the intergers fine.</p>
  
  <pre><code>$('#sub_category_box_systems').on('click', '.sub_category_link', function() {
      system = $(this).attr('data-system');
  });
  
  
  $('#find_btn').click(function(){
      alert(system);
      $.ajax({
          type: "POST",
          url: 'scripts/get_specimens_system.php',
          data: {
              system: system,
          },
          success: function(data) {
          }
      });
  });
  </code></pre>
  
  <p>AND I have updated the PHP file to:</p>
  
  <pre><code>$system = $_POST['system'];
  </code></pre>
  
  <p>Still no go, though if I swap the var <code>system</code> with the actual var of an array (for example, <code>heart</code>), as the Ajax data it works. So what's wrong here? (sorry for changing this OP...).</p>
  
  <p>Odd, if I change var <code>system</code> to a specific array like below it works, so there must be some problem with the formatting using the jQuery <code>.attr('data-system');</code></p>
  
  <pre><code>$('#sub_category_box_systems').on('click', '.sub_category_link', function() {
      system = heart;
  });
  </code></pre>