Send html array as post variable using Request.JSON
- by ian
I have an html:
First name: <input type='text' name='first_name' value='' /><br/>
Last name: <input type='text' name='last_name' value='' /><br/>
<input type='checkbox' name='category[]' value='Math' /> Math<br/>
<input type='checkbox' name='category[]' value='Science' /> Science<br/>
<input type='checkbox' name='category[]' value='History' /> History<br/>
etc.....
I want to send(using post method) the selected categories(category[]) via mootools ajax so that if I dump the $_POST variable in the server I will get something like:
array(1) {
[category]=>
array(2) {
[0]=>
string(4) "Math"
[1]=>
string(7) "History"
}
}
What should be the javascript(mootools) code for it? Below is my partial code.
new Request.JSON({url: '/ajax_url',
onSuccess: function(){
alert('success');
}
}).post(???);
Note that I don't want to send first_name and last_name fields. I only want to send the category field which is an html array.