Answer the question
In order to leave comments, you need to log in
How to pass the results of jquery each function as an array to php?
Friends, for the first time I encounter such a task, I look for examples on the net and I still can’t understand whether there is either each or arr
What I have:
There is an unknown number of option blocks, they have an option name and value
<div class="option">
<span class="current">Размер</span>
<div class="value">XL</div>
</div>
<div class="option">
<span class="current">Количество</span>
<div class="value">5</div>
</div>
$(".option").each(function(index, value) {
var thisoption = "";
var thisvalue = "";
thisoption += $(this).find('.current').text();
thisvalue += $(this).find('.value').text();
console.log(index + ': ' + thisoption +' = '+ thisvalue);
});
$.ajax({
type: "POST",
url: mailURL,
data: {
option: :((
},
})
Answer the question
In order to leave comments, you need to log in
var toSend = [];
$(".option").each(function(index, value) {
var thisoption = "";
var thisvalue = "";
toSend.push({
option: $(this).find('.current').text(),
value: $(this).find('.value').text()
});
});
sendToHandle();
function sendToHandle() {
$.ajax({
type: "POST",
url: mailURL,
data: toSend
})
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question