title: JQuery: 'Uncaught TypeError: Illegal invocation' at ajax request - several elements
body: <p>I have two select elements, A and B: when A's selected option changes, B's options must be updated accordingly. Each element in A implies many elements in B, it's a one-to-many relationship (A contains nations, B should contain cities located in the given nation).</p>
  
  <p>The function <code>do_ajax</code> should run the asynchronous request:</p>
  
  <pre><code>function do_ajax(elem, mydata, filename)
  {
      $.ajax({
          url: filename,
          context: elem,
          data: mydata,
          datatype: "html",
          success: function (data, textStatus, xhr) {
              elem.innerHTML = data;
          }
      });
  }
  </code></pre>
  
  <p>In order to update B's options I've added a function call in A's <code>onChange</code> event. Here is the function that runs when onChange event (of <code>A</code>) is triggered:</p>
  
  <pre><code>function my_onchange(e) // "e" is element "A"
  {
      var sel_B = ... ; // get select element "B"
  
      // I skipped some code here
      // ...
  
      var data = {
          'mode': 'filter_city',
          'id_A': e[e.selectedIndex]
      };
      do_ajax(city_sel, data, 'ajax_handler.php');
  }
  </code></pre>
  
  <p>}</p>
  
  <p>I've read in <a href="http://api.jquery.com/jQuery.ajax/">JQuery docs</a> that <code>data</code> can be an array (key value pairs). I get the error if I put:</p>
  
  <pre><code>var data = {
          'mode': 'filter_city',
          'id_A': e[e.selectedIndex]
  };
  </code></pre>
  
  <p>Instead, I don't get that error if my data is a string:</p>
  
  <pre><code>var data = 'mode=filter_city&amp;amp;id_A=' + e[e.selectedIndex];
  </code></pre>
  
  <p>But I need the "array version" of the variable, in my server-side php code. </p>
  
  <p>The <code>Uncaught TypeError: Illegal invocation</code> is located in the "jquery-1.7.2.min.js" file, which is all compressed, so I couldn't figure out what part of code raised the error.</p>
  
  <p>Is there any setting I can change in my code so that it accepts data as an associative array?</p>