Michael Michael - 1 month ago 4x
Ajax Question

JQuery on change make ajax request

I have a bunch of selects as filters like this

<select name="color" data-options="katalog.php?cat=3" class="filter">
<option value="1">White</option>
<option value="2">Green</option>

but in Firebug I get an error and can't figure out why

$('body').on("change", '.filter', function() {

$('#mainstage').load($(this).data('options') + '&' + $(this).attr('name') + '=' + $(this).attr('value'));


The url you are requesting is "katalog.php?cat=3&color=undefined" because you should not be using attr() to read the value. Use jQuery's val() method so you get the value of the option that was selected.

... '=' + $(this).val())