Michael Michael - 1 year ago 98
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'));

Answer Source

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())
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download