I studied this on other StackOverFlow questions and I cannot find the answer.
I have a form.
<input name="item[1]" class="item" value="1">
<input name="item[2]" class="item" value="50">
<input name="item[3]" class="item" value="12">
I try to get the results of each input of an element and send them through Ajax to my controller, this is normal when using the action = "" method, but through ajax I can not format the data into an array.
Can someone tell me what I did wrong?
$('button#despatchOrder').on('click', function() {
var values = $("input.items");
var myArray = $.map(values, function(value, index) {
return [value];
});
console.log(myArray);
});
Unfortunately, jQuery is not my strongest language, but I am learning. I expected the result to be something like.
items = [
1 => 1,
2 => 50,
3 => 12
]
But I have everything related to the input like
Input 1 = [
accept
accessKey
alt
etc
etc
]
source
share