My Jquery is
$(":checkbox").change(function() {
if(this.checked) {
var man_data = { 'man': [] };
var size_data = { 'size': [] };
var color_data = { 'color': [] };
$('input:checked').each(function ()
{
if(this.name == 'man') man_data['man'].push($(this).val());
if(this.name == 'size') size_data['size'].push($(this).val());
if(this.name == 'color') color_data['color'].push($(this).val());
});
var path = "/Home/Index";
$.ajax({
url: path, type: "POST", cache: "false",
dataType: "json", contentType: "application/json; charset=utf-8",
data: JSON.stringify(man_data),
traditional: true,
converters: {'text json': true}
}).success(function (responseText) {
$('#Grid').replaceWith(responseText);
}).error(function (responseText){
swal("Error!", "Test 1", "error");
});
//swal("Error!", "Test 2", "error");
}
});
If i post only one array data: JSON.stringify(man_data) it works great.
The problem is that i would like to post the contents of all the 3 arrays
- man_data
- size_data
- color_data
I tried something like
data: JSON.stringify(man_data + size_data + color_data)
but it is not working as expected :(
How should i modify the code above?
I also tried something like
data: {'man':JSON.stringify(man_data),'size':JSON.stringify(size_data)},
but now i get the error Invalid JSON primitive: man.
UPDATE
The data are sent at an MVC controller
public ActionResult Index(int[] man = null, int[] size = null, int[] color = null)
{
}
man_data.concat(size_data, color_data)?