title: How to pass array from ajax to php?
body: <p>I'm trying to pass array from ajax to php (controller). </p>
  
  <p>What is wrong with second code as <code>var_dump($data)</code> of first code returns appropriate content and second returns NULL?</p>
  
  <p>FIRST. GOOD.</p>
  
  <pre><code>function myFunction() {
      var elementy = document.getElementsByClassName('inputISBN');
      var data = elementy[0].value;
  
      $.ajax({
             url: "{{ path('test') }}",
             type: "POST",
             data: { "data": data }
  
      });   
  
  }
  </code></pre>
  
  <p>SECOND. BAD</p>
  
  <pre><code>function myFunction() {
      var elementy = document.getElementsByClassName('inputISBN');
      var data = [];    
      data[elementy[0].name] = elementy[0].value;
  
      $.ajax({
             url: "{{ path('test') }}",
             type: "POST",
             data: { "data": data }
      });   
  }
  </code></pre>
  
  <p>THIRD. UGLY</p>
  
  <pre><code>var elementy = document.getElementsByClassName('inputISBN');
  undefined
  var data = []; 
  undefined
  data[elementy[0].name] = elementy[0].value;
  "667"
  </code></pre>
  
  <p>Third one is line by line  from the socond code written in browser console. And it's return what it should.</p>
  
  <hr>
  
  <p>edit</p>
  
  <p>and data is pulled out from here:</p>
  
  <pre><code>&lt;input type="number" class="inputISBN" size="2" name="exampleName" 
                  value="666" onchange="myFunction()"&gt;
  </code></pre>