Send html array as post variable using Request.JSON

Posted by ian on Stack Overflow See other posts from Stack Overflow or by ian
Published on 2010-05-18T02:05:59Z Indexed on 2010/05/18 2:10 UTC
Read the original article Hit count: 228

Filed under:
|
|
|
|

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.

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about mootools