I have two select elements: A and B: when a selected option is selected, options B must be updated accordingly. Each element from A implies many elements in B, this is a one-to-many relationship (A contains nations, B must contain cities located in a given country).
The do_ajax function should start an asynchronous request:
function do_ajax(elem, mydata, filename) { $.ajax({ url: filename, context: elem, data: mydata, datatype: "html", success: function (data, textStatus, xhr) { elem.innerHTML = data; } }); }
To update options B, I added a function call to the A onChange event. Here is the function that fires when the onChange ( A ) event fires:
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'); }
}
I read in jQuery docs that data can be an array (key value pairs). I get an error if I put:
var data = { 'mode': 'filter_city', 'id_A': e[e.selectedIndex] };
Instead, I do not get this error if my data is a string:
var data = 'mode=filter_city&id_A=' + e[e.selectedIndex];
But I need a "version of the array" of this variable in my server side php code.
Uncaught TypeError: Illegal invocation is in the jquery-1.7.2.min.js file, which is all compressed, so I could not figure out which part of the code raised the error.
Is there any parameter that I can change in my code so that it accepts data as an associative array?