jQuery Ajax Request Based on Checkboxes
Me again,
Trying to learn some jQuery stuff. Now I'm building an AJAX search engine. AJAX request should depend on the checkboxes values.
I have multiple groups of checkboxes: band[], genere[] and type[]. However I'm stuck with sending proper AJAX request to the PHP script.
My code:开发者_JS百科
$("input.filter").click(function() {
if( $("input.filter:checked").length )
sendRequest('type=ajax&target=display&' + $("input.filter").serialize());
else
sendRequest('type=ajax&default=true&target=display')
});
Issue: It's not working on checking ant checkbox, it works when the second checkbox is selected or when checkbox is unchecked. Generally, very buggy.
Can anybody provide suggestions or proper function name that can help me solve this issue?
My checkboxes looks like this one:
<input type="checkbox" name="band[]" class="filter" value="blind guardian" />
The square brackets []
are needed for multiselect, it is good that way.
Your serialized string should be working server side, like an array:
key[]=A&key[]=B&key[]=C
would be:
Array (
0 => "A",
1 => "B",
2 => "C"
)
There must be something else, if it does not work. What is the main problem, you experience:
- click handler won't fire?
- serialize create bad data?
- bad ajax response?
精彩评论