var checkedValues = $('.required:checked').map(function() {
return this.value;
}).get();
var arr = new Array(10);
alert(checkedValues);
alert("number of values in it " +checkedValues.length);
if (checkedValues.length > 1) {
alert("I am inside if ");
arr = checkedValues.split(',');
alert("I am done with the split ");
}
else {
arr = checkedValues;
alert("No split needed ");
}
$.getJSON('@Url.Action("testcata", "home")' + + '?Type=' + "@(Session["typ"])" + "&city=" + "@(Session["cit"])" + "&chkd=" + checkedValues,
function (data) {
//code
})
In controller :
public ActionResult testcata(string Type, int? city, int[] chkd)
{
//code
}
我想获取检查框的值,并将它们存储在数组中,然后通过json函数发送给控制器。警报(“我已完成拆分”)未显示。请帮帮我。如何解析表单数据以在jQuery中使用JSON?
使用控制台日志而不是警报 – 2014-09-19 12:56:52
可以显示html吗? – Sablefoste 2014-09-19 12:57:21
'checkedValues'已经是一个数组。你想要分裂什么? – 2014-09-19 12:59:28