Answer the question
In order to leave comments, you need to log in
How to pass several arrays to 1 php file from js using AJAX?
For example, there are such arrays in JS:
let arr1 = [1, 2, 3, 4, 5];
let arr2 = ['a', 'b', 'c', 'd', 'e'];
Answer the question
In order to leave comments, you need to log in
This is all done quite simply. Below is an example of sending data using jQuery.ajax()
async function sendInfo() {
let arr1 = [1, 2, 3, 4, 5];
let arr2 = ['a', 'b', 'c', 'd', 'e'];
var response = await $.ajax({
url: 'test.php',
method: 'POST',
cache: false,
data: {
'arr1': arr1,
'arr2': arr2
}
});
console.log('Данные успешно отправлены, ответ сервера: ' + response);
return response;
}
</head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
Make a wrap?
let a = {
mas1:[1,2,4,5,6,],
mas2:['asd','as2']
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question