title: Send to AJAX name and value of selected option
body: <p>I am trying to send through ajax the name and the value of a selected option in a dropdown menu so as to be able to launch a sql-request including the selected option.</p>
  
  <p>Here is what I have so far:</p>
  
  <p>jQuery:</p>
  
  <pre><code>$('#form_stadt_kanton').select(function() {
      var kanton = $('#form_stadt_kanton').find(":selected");
      $.ajax({
                  // Daten sammeln
                  url: "wholephp.php",  // Selbe Domain
                  cache: false,
                  type: "GET",
                  dataType: "text",
                  data: kanton,
                  success: function(para) {
                      $("#allecheckboxes").html(para)
                      drawMarkersMap()
                  } // Ende Function
              }) // Ende ajax
              ereignis.preventDefault(); //Stop der Formular-Aktion
  }) //Ende function
  </code></pre>
  
  <p>and html/php:</p>
  
  <pre><code>&lt;form method="GET" action="" id="form_stadt_kanton"&gt;
          &lt;table&gt;
              &lt;tr&gt;&lt;th&gt;&lt;label for="stadt"&gt;Nach &lt;b&gt;Stadt&lt;/b&gt; filtern:&lt;/label&gt;&lt;/th&gt;&lt;/tr&gt;
              &lt;tr&gt;&lt;td&gt;&lt;input type="text" id="stadteingabe" value="Stadt eingeben"&gt;
  </code></pre>
  
  <p>
              </p>
  
  <pre><code>        &lt;table class="tablefloatright"&gt;
              &lt;tr&gt;&lt;th&gt;&lt;label for="kanton"&gt;Nach &lt;b&gt;Kanton&lt;/b&gt; filtern:&lt;/label&gt;&lt;/th&gt;&lt;/tr&gt;
              &lt;tr&gt;&lt;td&gt;&lt;select&gt;&lt;option id=""&gt;Kanton auswählen&lt;/option&gt;
              &lt;?php
              $i = 1;
              foreach ($kantone as $kanton) {
                  echo "&lt;option name='kanton".$i."' value='".$kanton."'&gt;".$kanton."&lt;/option&gt;";
                  $i=$i+1;
              } 
              ?&gt;
              &lt;/select&gt;&lt;/td&gt;&lt;/tr&gt;
          &lt;/table&gt;
          &lt;/form&gt;
  </code></pre>
  
  <p>In the php-file "wholephp.php", I would like to be able to use the following code: <code>foreach($_GET as $name =&gt; $wert)</code>
  That's why I need to get the name of the option along with its value. Depending on what the "name" is, the WHERE condition is different.</p>
  
  <p>I would greatly appreciate any help in this matter. It can't be too complicated, but I just don't get it. Any ideas?</p>
  
  <p>Many thanks in advance!</p>
  
  <p>EDIT:
  I could finally solve the problem with serializeArray(). Here is what the (working) code looks like:</p>
  
  <p>jQuery / Ajax:</p>
  
  <pre><code>$(document).on('change', 'select', function(){
      //var kanton = $('#form_stadt_kanton').find(":selected");
      var kanton = $('#form_stadt_kanton').serializeArray();
      $.ajax({
                  // Daten sammeln
                  url: "wholephp.php",  // Selbe Domain
                  cache: false,
                  type: "GET",
                  dataType: "text",
                  data: kanton,
                  success: function(para) {
                      $("#allecheckboxes").html(para)
                      drawMarkersMap()
                  } // Ende Function
              }) // Ende ajax
              ereignis.preventDefault(); //Stop der Formular-Aktion
  }) //Ende function
  </code></pre>
  
  <p>HTML / PHP:</p>
  
  <pre><code>&lt;form method="GET" action="" id="form_stadt_kanton"&gt;
          &lt;table&gt;
              &lt;tr&gt;&lt;th&gt;&lt;label for="kanton"&gt;Nach &lt;b&gt;Kanton&lt;/b&gt; filtern:&lt;/label&gt;&lt;/th&gt;&lt;/tr&gt;
              &lt;tr&gt;&lt;td&gt;&lt;select name='kanton'&gt;&lt;option value="" selected='selected'&gt;Kanton auswählen&lt;/option&gt;
              &lt;?php
              $i = 1;
              foreach ($kantone as $kanton) {
                  echo "&lt;option value='".$kanton."'&gt;".$kanton."&lt;/option&gt;";
                  $i=$i+1;
              } 
              ?&gt;
              &lt;/select&gt;&lt;/td&gt;&lt;/tr&gt;
          &lt;/table&gt;
          &lt;/form&gt;
  </code></pre>