1 回答
TA贡献1877条经验 获得超1个赞
由于有多个值,您可以使用多个值向其添加多个值,并将其发送到ajax。divsarray
演示代码 :
document.getElementById("done_editing").addEventListener("click", get_values);
var OBJ = [];
function get_values() {
let divobj = document.querySelectorAll('[contenteditable=true]')
for (var i = 0; i < divobj.length; i++) {
OBJ.push(divobj[i].textContent); //add in array
}
console.log(OBJ)
//your ajax call
$.ajax({
type: 'POST',
url: 'test.php',
data: {
OBJ: OBJ //pass array to php
},
success: function(data) {
alert("something");
}
});
}
div {
border: 1px solid;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div contentEditable="true"></div>
<div contentEditable="true"></div>
<div contentEditable="true"></div>
<div contentEditable="true"></div>
<button id="done_editing">Done</button>
你的 php 将如下所示:
<?php
// You should call this first
session_start();
$data = isset($_POST['arraykey']);
if ($data)
{
$_SESSION['arraykey'] = $_POST["arraykey"];//putting aray value in session
echo $_SESSION['arraykey'];
echo " is your array";
}
else
{
echo "no array supplied";
}
?>
添加回答
举报