The AJAX way:
From the jquery documentation for AJAX:
data
Type: PlainObject or String
Data to be sent to the server. It is
converted to a query string, if not already a string. It's appended to
the url for GET-requests. See processData option to prevent this
automatic processing. Object must be Key/Value pairs. If value is an
Array, jQuery serializes multiple values with same key based on the
value of the traditional setting (described below).
traditional
Type: Boolean
Set this to true if you wish to use the
traditional style of param serialization.
var roleList = new Array();
var usrId = "testuser";
/* one way of adding items to array */
roleList.push(1);
roleList.push(5);
roleList.push(8);
$.ajax({
type: "POST",
traditional: true, /* I M P O R T A N T */
url: /* url to controller goes here */,
data: { userId: usrId, allowedRoles: roleList },
success: function(returndata) {
alert("Done");
},
error: function(returndata) {
alert("Error:\n" + returndata.responseText);
}
});