Answer the question
In order to leave comments, you need to log in
Why does the ajax method of collecting a value using each (took the value of several inputs) accept only one?
$('.send').click(function(){
let val;
let name;
$('.answer').each(function(item){
val = $(this).val()
name = $(this).attr('name')
// console.log(val)
})
$.ajax({
type:"post",
url:"server.php",
data:{action:"test",value:val,name:name},
success:function(r){
r = JSON.parse(r)
console.log(r)
}
})
})
Answer the question
In order to leave comments, you need to log in
so every time you overwrite the values of the variables val and name in each, it is logical that only the last ones will remain. save to an array or something) and there is also a serialization of the form, this is a function, similar to what you tried to do
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question