function BuildParams(arr)
{
// arr is an Array
// how to build params based on the length of the array?
// for example when arr.Length is 3 then it should build the below:
var params = {
'items[0]' : arr[0],
'items[1]' : arr[1],
'items[2]' : arr[2]
},
return params;
}
然后我希望能够将它发送到我的 ajax 获取:
var arr = ['Life', 'is', 'great'];
$.get('/ControllerName/ActionName', BuildParams(arr))
.done(function(data, status) {
alert("Data: " + data + "\nStatus: " + status);
})
.fail(function(data) {
alert(data.responseText);
});