gpt4 book ai didi

php - Ajax 从填充的数据表中获取列文本并在 PHP 中使用它

转载 作者:行者123 更新时间:2023-11-30 21:58:57 28 4
gpt4 key购买 nike

我有一个数据表,我想从中获取单击单元格中的文本并将其用作 PHP 中的变量,以便我使用该变量来查询 mysql。到目前为止我的代码如下:

<script type="text/javascript">

$(document).ready( function () {
$('#priority tbody').on('click', 'tr', function() {
var celldat = $(this).find('td:first').text(); //gets the text from the first column when a row is clicked.
$.ajax({
url: 'prioritize.php', //my url
method: "POST",
async: 'false',
data: {variable:celldat},
success: function(data) {
alert(celldat); //The alert is perfect. It returns the text from the first column.
window.location.reload(true);
}
})
});
});
</script>

在我的 PHP 中,我试图回显相同的值:

<?php
$selected=$_POST['variable'];
echo $selected;
?>

但它不起作用。本质上,我想在 mysql 选择查询中使用 $selected 来填充另一个表。

最佳答案

在数据中:尝试像这样:"data: {variable:"+celldat"}"

尝试这样做 $_POST['data'] 这将为您提供从 ajax 请求发送的所有数据

关于php - Ajax 从填充的数据表中获取列文本并在 PHP 中使用它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44095230/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com